PoPs
PoPs

Reputation: 15

How can I exclude a user with a specific id in MySQL

How can I exclude a user with a user_id of 1 for example from the following query below?

Here is My MySQL code.

"SELECT users.*, COUNT(*) as coun, users_comments.user_id 
FROM users_comments
INNER JOIN users ON users_comments.user_id = users.user_id
GROUP BY users_comments.user_id 
ORDER BY coun DESC
LIMIT 5"

Upvotes: 1

Views: 97

Answers (2)

Aman Nehra
Aman Nehra

Reputation: 11

SELECT users.*, COUNT(*) as coun, users_comments.user_id 
FROM users_comments
JOIN users ON users_comments.user_id = users.user_id
WHERE users.user_id not in(1,3) 
GROUP BY users_comments.user_id 
ORDER BY coun DESC
LIMIT 0,5

Upvotes: 0

Krevan
Krevan

Reputation: 1681

SELECT users.*, COUNT(*) as coun, users_comments.user_id 
FROM users_comments
INNER JOIN users ON users_comments.user_id = users.user_id
WHERE users.user_id != 1 <---------------
GROUP BY users_comments.user_id 
ORDER BY coun DESC
LIMIT 5

Upvotes: 3

Related Questions