Wordica
Wordica

Reputation: 2597

Check if one table has other table related by id

I have User table where every user has entry and every User has entry in Profile table with user_id form User table, How can I check if:

Select FROM table.users where(table profiles do not exist based od user_id ) 

I deleted manually some entry in Profile table and now I want find entry in User table which do not have entry in Profile table

Upvotes: 0

Views: 39

Answers (1)

ivardepievar
ivardepievar

Reputation: 36

SELECT users.* FROM users
LEFT JOIN profiles ON (users.id = profiles.user_id)
WHERE profiles.user_id IS NULL

Upvotes: 2

Related Questions