SQL FULL JOIN超过6个表

时间:2012-12-03 11:07:02

标签: c# mysql sql

我有几张桌子。有人可以告诉我我必须使用哪个联盟?

Table Factory : FactoryId, FactoryName

Table Person: PersonId, PersonName

Table Activity : AcitivityId, AcitivityType

Table FactoryPersonActivity: FactoryID, PersonId, ActivityId

Table AcitivityLead: AcitivityId, LeadId

Table Lead: LeadId, LeadType, LeadMethod

现在的问题是:我想要某个工厂的所有潜在客户(详细信息)。有人能告诉我连接声明必须是什么吗?

提前致谢!!

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT 
  l.LeadType,
  l.LeadMethod
  f.Name
  p.PersonNASme,
  ...
FROM Factory f 
INNER JOIN FactoryPersonActivity fpa ON f.FactoryId    = fpa.FactoryID
INNER JOIN Person                  p ON fpa.PersonID   = p.PersonId
INNER JOIN Activity                a ON fpa.ActivityID = a.ActivityId
INNER JOIN AcitivityLead          al ON a.AcitivityId  = al.AcitivityId
INNER JOIN Lead                    l ON a.LeadId       = al.LeadId
WHERE f.FactoryID = $id;

请详细了解JOIN