Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add results from several COUNT queries

Tags:

sql

mysql

I am trying to fetch the sum of several counts in one query:

SELECT(
    SELECT COUNT( * )
    FROM comments +
    SELECT COUNT( * )
    FROM tags +
    SELECT COUNT( * )
    FROM search
)

I am missing something here. I get syntax error.

like image 744
Itay Moav -Malimovka Avatar asked Jul 21 '09 17:07

Itay Moav -Malimovka


1 Answers

SELECT ( SELECT COUNT(*) FROM comments ) 
     + ( SELECT COUNT(*) FROM tags ) 
     + ( SELECT COUNT(*) FROM search )
like image 162
Matt Rogish Avatar answered Nov 16 '22 02:11

Matt Rogish