If we have two tables, say; “users”, and “images”, how do we select users who have at least X number of images? I believe I need to be using COUNT(), but unsure on the overall syntax…
The “users” table as an user_id field, and each image in the “images” row has an “user_id”, so the two table tables can be joined using those.
I tried:
SELECT users.*, SELECT COUNT(*)
FROM images
WHERE images.user_id=users.user_id AS num_images
WHERE num_images>2
But no luck – the syntax is wrong, but unsure how you correctly do an inner query, or just join the table where there is at least 2 rows in the images table.
1 Answer