To get the merits from category X that user Y has:
SELECT m.merit_id, m.merit_name
FROM merits m
JOIN users_merits um ON m.merit_id = um.merit_id
WHERE m.cat_id = X
AND um.uid = Y
To get all the merits from category X:
SELECT m.merit_id, m.merit_name
FROM merits m
WHERE m.cat_id = X
EDITED: To get all the merits from category X, and show the ones user Y already has at the top (I am guessing that's what you meant):
SELECT m.merit_id, m.merit_name, um.uid as `user`
FROM merits m
LEFT JOIN users_merits um ON m.merit_id = um.merit_id AND um.uid = Y
WHERE m.cat_id = X
ORDER BY user, m.merit_name DESC
Explanation:
The LEFT JOIN attaches records from users_merits table to records from merits table, if there are records to attach.
That means, that for every record in merits that satisfies the WHERE clause, the DB will try to match a record (or records) from *users_merits* that satisfy the condition in the ON clause.
Being a LEFT JOIN (unlike a simple JOIN), all the records from the main table (merits) will be shown even if they have no matches in *users_merits* - as long as they satisfy the WHERE clause. Originally I put the uid = Y in the WHERE clause, so merits that were not received by user Y were not showing.
Finally we get a table of merits, all of them from category X, some of them achieved by user Y - those have a uid attached to them while others have NULL. ORDER BY uid puts the ones with the uid above the ones with NULL.
P.S. My SQL is better than my English, hope this is helpful :)