Hello. I currently am working on developing an application. For reference, the related mysql tables look like this (slimmed down to applicable fields):
`users`
---------------------------------------
`id` int unsigned
`privacy` enum('EVERYONE','FRIENDS')
`quotes_tags`
---------------------------------------
`qt_id` int unsigned
`subject` int unsigned
Subject is a foreign key, `id` on `users`.
I am trying to get the user id (same as subject) of the 5 people who have the most entries in `quotes_tags`. In the same query, I am trying to also get that user's `privacy` entry.
And here is the current query that I am currently using:
Code:
SELECT
quotes_tags.subject,
users.privacy_setting AS privacy,
COUNT(quotes_tags.subject) AS count
FROM `quotes_tags`, `users`
GROUP BY subject
ORDER BY count DESC
LIMIT 0, 5
And that will return a dataset that looks something like:
Code:
+-----------+----------+-------+
| subject | privacy | count |
+-----------+----------+-------+
| 2 | EVERYONE | 8 |
| 1 | EVERYONE | 4 |
| 568623702 | EVERYONE | 4 |
+-----------+----------+-------+
However, the data is incorrect. 568623702's privacy is FRIENDS, and all of the counts are wrong.
If you can see what I'm trying to do, please help me get my query straightened up. If you are confused about what I'm trying to do, I will try to explain more, or create a simplified case with simple data.
Thanks a lot!
Jonathon[/code]