2013-04-18 60 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

相关问题