Helmi Helmi - 3 months ago 10
SQL Question

Select users from table that have at least one entry in diffierent table

I'm looking for a way to select users from a user table that have at least one relating entry in another table. Probably my join approach is totally wrong but that is what I was trying and should give you an idea of the structure:

SELECT users.`id`, users.`email`, users.`username`, users.`status`, users.`date_reg`
FROM dir_editors as users
JOIN dir_links as links ON (links.`id_editor` = users.`id`)
WHERE COUNT(links.`id_editor`) > 1


So the goal is to get all these user data from user that have at least one link entry in the
dir_links
table where the
id_editor
is the field in the dir_links table.

Thanks for helping

Answer
SELECT users.`id`, users.`email`, users.`username`, users.`status`, users.`date_reg`
 FROM dir_editors as users
WHERE EXISTS(SELECT 1 FROM dir_links as links WHERE links.`id_editor` = users.`id`)