a noob question here!
I wrote this query, but the \"group by\" is very stupid... so, how can I correct this?
SELECT
COUNT(*) AS total,
\'x\'
Let's dissect your query:
SELECT
COUNT(*) AS total,
'x' as test <-- Why?
FROM <-- Bad formatting.
contents
WHERE name LIKE 'C%'
GROUP BY
test <-- Removing 'x' and the whole GROUP BY has the same effect.
ORDER BY id ASC <-- The result only contains one row - nothing to sort.
So the query that returns one row with one field, containing the number of rows whose name begins with 'C' would look like this:
SELECT COUNT(*)
FROM contents
WHERE name LIKE 'C%'
Having an index whose leading edge is name would ensure good performance. To understand why, take a look at the Anatomy of an SQL Index.