Reputation: 121
I have two tables
How to select users that have optionName = 'email' and value = 1 or have no entries for email in the Options table?
Upvotes: 1
Views: 57
Reputation: 172578
Try this:
select * from User u inner join Option o on u.id = o.userid
where (o.optionName = 'email' and o.value = 1) or (o.optionName <> 'email')
Upvotes: 2
Reputation: 4749
THis might help you:
"SELECT * from users u left join options o on u.id = o.userid where (o.optionName = 'email' and o.value = 1) or o.userid is null; ";
Upvotes: 0