2013-04-18 76 views

回答

6

這裏有一種方法:

select (select count(*) from table1) as t1_amount, 
     (select count(*) from table2) as t2_amount 

這裏是另一種方式:

select t1.t1_amount, t2.t2_amount 
from (select count(*) as t1_amount from table1) t1 cross join 
    (select count(*) as t2_amount from table2) t2 

你的方法行不通,因爲from子句中的,做了cross join。這是兩張桌子之間的笛卡爾產品。

+0

感謝戈登哪種方法更有效? – Bruce

+0

@ bluebill1049。 。 。在效率方面它們應該是一樣的。就個人而言,我更喜歡第二種方法,因爲我傾向於避免在select語句中選擇select。 –

+0

謝謝戈登,我會按照你的建議 – Bruce

1

由於他們是兩個單獨的查詢,並且希望他們在相同的結果集,使用UNION:

+0

謝謝約書亞的答案 – Bruce

相關問題