Table:
person | ethnicity
james | white
bill | african
Lina | african
Ruby | Latin
josh | Latin
SQL query 1:
SELECT * FROM
(select count(*) from MyTable where ethnicity = 'white') sub,
(select count(*) from MyTable where ethnicity = 'Latin') sub2
SQL query 2:
SELECT COUNT(ethnicity) as ehtCount, ethnicity
FROM MyTable
GROUP BY ethnicity
The result would be same in both cases. Which SQL is faster?
count(*)
. I'm guessing you didn't even try it, otherwise you wouldn't need to ask me because you would see for yourself what I meant by my first comment.)