SQL: Combine Select count(*) from multiple tables

后端 未结 8 650
迷失自我
迷失自我 2020-12-08 13:08

How do you combine multiple select count(*) from different table into one return?

I have a similar sitiuation as this post

but I want one return.

I t

8条回答
  •  醉酒成梦
    2020-12-08 13:52

    Basically you do the counts as sub-queries within a standard select.

    An example would be the following, this returns 1 row, two columns

    SELECT
     (SELECT COUNT(*) FROM MyTable WHERE MyCol = 'MyValue') AS MyTableCount,
     (SELECT COUNT(*) FROM YourTable WHERE MyCol = 'MyValue') AS YourTableCount,
    

提交回复
热议问题