How to make multiple counts in one query?
To get a count for each of those you can try
SELECT
COUNT(CASE WHEN `col1` LIKE '%something%' THEN 1 END) AS count1,
COUNT(CASE WHEN `col1` LIKE '%another%' THEN 1 END) AS count2,
COUNT(CASE WHEN `col1` LIKE '%word%' THEN 1 END) AS count3
FROM `table1`;
Similar to Aaron's solutio, shorter syntax:
SELECT
SUM(col1 LIKE '%something%') AS count1,
SUM(col1 LIKE '%another%') AS count2,
SUM(col1 LIKE '%word%') AS count3
FROM `table1`
The LIKE expression makes for a boolean result. TRUE
is 1, FALSE
is 0, so the CASE
is redundant here.