0

我有 3 张桌子。喜欢:B001,B002,B003

每个表都有Entrynumber列。

所以我必须在所有 3 个表中找到Entrynumber值是否存在。

就像我们为一张桌子写的:

select count(*) from B001  Where Entrynumber ='3340'

我想知道加入表格的最佳方式是什么。

4

3 回答 3

1

使用内连接

select count(*) 
from B001 b1
inner join B002 b2 on b1.Entrynumber = b2.Entrynumber 
inner join B003 b3 on b1.Entrynumber = b3.Entrynumber 
Where b1.Entrynumber ='3340'

获取Entrynumber所有表中存在的记录数。

于 2013-10-10T07:52:03.027 回答
0
SELECT COUNT(*) FROM B001
INNER JOIN B002 ON (B001.Entrynumber = B002.Entrynumber AND B002.Entrynumber = '3340')
INNER JOIN B003 ON (B001.Entrynumber = B003.Entrynumber AND B003.Entrynumber = '3340')
WHERE B001.Entrynumber = '3340'

内连接条件是最好的方法。

于 2013-10-10T08:19:23.263 回答
0

在所有表中查找值

 select
      (select count(*) from b001 where EntryNumber = '3340') b1Count,
      (select count(*) from b002 where EntryNumber = '3340') b2Count,
      (select count(*) from b003 where EntryNumber = '3340') b3Count
于 2013-10-10T08:13:27.003 回答