2013-12-12 19 views
0

我有三個表Pub,0 Boo,PerSQL如何找出數據位於哪個表

Boo.numPub.serial

Per.num一提的是,以Pub.serial參考(指Pub大約有兩​​個人的信息)

我想知道一排Pub屬於PerBoo

我該怎麼做?

(我只需要一個附加的字段具有0或另一數量,以確定其中哪一個數據屬於)

認爲它是酒吧既啵和Per和這些表的父是Pub的類型。

+1

它叫做關係。去谷歌主鍵外鍵 – Namphibian

+2

想象一下,人們在SO上發佈他們的代碼......只是想象。 – Kermit

+0

@FreshPrinceOfSO這將是一個歡樂的一天。 – Namphibian

回答

1

我真的不知道,如果這是你在找什麼,但它是值得一試:

select Pub.serial, 
    (select count(*) from Boo where Boo.num = Pub.serial) as Boo_Count, 
    (select count(*) from Per where Per.num = Pub.serial) as Per_Count 
From Pub 
Order by Pub.serial 
+0

非常感謝你的男人。我以爲我嘗試過,但我的版本不起作用。這解決了它。正是我想要的 – Arijoon

+0

很酷。很高興幫助! – BWS

0

你想

SELECT Boo.num, per.num 
FROM Pub 
LEFT JOIN Boo ON Pub.serial=Boo.num 
LEFT JOIN Per ON Pub.serial=Per.num 

,看看哪些人有數據。

+0

返回零結果! – Arijoon

相關問題