Reputation: 11374
I want to select users only who submitted a profile picture. I have two tables, users
and users_info
.
The users
table holds basic information about the user
The users_info
table holds information which is used in addition to the basic information
I would be able to do this using PHP to grab a bunch of users and only go with those with images, but I'd prefer doing it using a single query. How can i accomplish this?
Upvotes: 1
Views: 51
Reputation: 85046
This should do it:
SELECT u.id
FROM users as u
INNER JOIN users_info as ui
ON u.id = ui.user_id
WHERE profile_image is not null
If you aren't familiar with joins, I would recommend giving this post a read. It is the best I've found for introducing people to the concept.
Upvotes: 2
Reputation: 1
select t1.*, t2.*
from users t1
inner join users_info t2 on t1.id = t2.id
where t2.profile_image is not null
-- note the where clause is not necessary if every user info record has a profile image.
Upvotes: 0