我有4张桌子:
1- resellers [id, name, etc..]
2- resellers_match [id, reseller_id, company_id]
3- companies [id, name, etc..]
4- products [id, name, company_id, etc..]
我需要从company_id与company_id.reseller_match和reseller.reseller_match = x匹配的产品中选择*;
我无法找到如何做到这一点。谢谢。
答案 0 :(得分:1)
SELECT p.name as Product, c.name as Company, r.name as Reseller
FROM products p
INNER JOIN companies c ON c.id = p.company_id
INNER JOIN resellers_match rm ON c.id = rm.reseller_id
INNER JOIN reseller r ON rm.reseller_id = r.id
ORDER BY p.name