Please don't beat me if this is elementary. I searched and found disjointed stuff relating to pseudo columns. Nothing spot on about what I need.
Anyway... I have a table with some rows. Each record has a unique ID, an ID that relates to another entity and finally a comment that relates to that last entity.
So, I want to COUNT these rows to basically find what entity has the most comments.
Instead of me explaining the query, I'll print it
SELECT entity_id, COUNT(*) AS amount FROM comments GROUP BY entity_id ORDER BY amount DESC
The query does just what I want, but I want to echo the values from that pseudo column, 'amount'
Can it be done, or should I use another method like mysql_num_rows?
Thank you!!!
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `comments` ADD INDEX `comments_idx_entity_id` (`entity_id`);
SELECT
comments.entity_id,
COUNT(*) AS amount
FROM
comments
GROUP BY
comments.entity_id
ORDER BY
amount DESC