根据我的评论,您得到的查询结果是正确的,因为表
contacts
user_providers
除了
user_id
柱
用户id
中的所有三行都是相同的
number of contacts for specific user id * number of user providers for a specific user id
例如,在没有
provider_name
在where子句中,获取您:3(联系人)*2(提供者)
id contact_name provider_name
-------------------------------
1 Vacio google
2 Vacio2 google
3 Vaciogiogle google
1 Vacio facebook
2 Vacio2 facebook
3 Vaciogiogle facebook
联络
user\u提供程序
桌子。例如,添加
provider_id
表中存储提供者的ID
桌子然后,您可以使用下面的SQL连接表,并在
提供商名称
SELECT c.id, c.contact_name, up.provider_name
FROM contacts c
LEFT JOIN user_providers up ON c.provider_id = up.provider_id
WHERE c.user_id = 1 AND up.provider_name = 'google';