如何INNER JOIN多个表?

时间:2016-06-14 16:30:23

标签: mysql

我有4张看起来像这样的表:

dog
ID
<numerous fields>
vetID

client
ID
<again, numerous fields I don't think are relevant>

vet
ID
<More irrelevant fields>

dogclient
ID
DogID
ClientID

我正在尝试从所有这些表中获取特定狗的ID的所有信息。我在PDO准备语句中尝试了这个查询

SELECT dog.*, client.*, vet.* 
FROM dogclient 
INNER JOIN client ON dogClient.ClientID = client.ID 
INNER JOIN dog ON dogclient.DogID = dog.ID 
INNER JOIN dog.vetID = vet.ID 
WHERE dogclient.dogID = :id

结果是查询中的语法错误:

'.ID WHERE dogclient.dogID = '4''

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

Dim companiesLookup = companys.ToLookup(Function(c) c.CompanyID)

Dim duplicates = companiesLookup.Where(Function(c) c.Count > 1).ToList

你错过了最后一次内部联接中的兽医表