I want to compare the count between two tables. Or more to say, output if the count from table1 is greater than from table2:
SELECT c1 > c2 FROM (SELECT count(*) from table1) as c1, (SELECT count(*) from table2) as c2
(real world selects are much more complex, but same structure)
Result: Unknown column 'c1' in 'field list'
How can I actually evaluate the counts?
Advertisement
Answer
Name the columns:
SELECT c1.cnt > c2.cnt FROM (SELECT count(*) as cnt from table1) c1 CROSS JOIN (SELECT count(*) as cnt from table2) c2