I have this tables: users contacts and user_providers, this is the structure of each one:
I want to get all the contacts from a specific user id in contacts table and user_provider provider_name in user_providers , i have this query
SELECT c.id, c.contact_name,c.description,c.discharge,c.latitude,c.longitude,c.town,c.country,c.province,
(SELECT array_agg(DISTINCT cn.number) FROM contact_numbers cn WHERE cn.contact_id = c.id) AS numbers,
(SELECT array_agg(DISTINCT ce.email) FROM contact_emails ce WHERE ce.contact_id = c.id) AS emails
FROM
contacts c,
user_providers po
WHERE
c.user_id = 1 and po.provider_name = 'google'
ORDER BY
c.id;
But when im trying to get the data it comes like this:

The query doesnt respect the provider_name, it returns all contacts related only with a specific user id.
Image from stored data:
contactsTable
user_provider Table

I appreciate any help!



provider_namedata for the 3 rows that you have in the picture?provider_name, they are from a specific user, and i want to get all thecontactsfrom a specific user and provider_name,i will add some photos about the info in the database