Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

mysql

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

like image 476
Helmi Avatar asked Oct 28 '25 13:10

Helmi


1 Answers

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`)
like image 197
Mike Avatar answered Oct 30 '25 05:10

Mike