I need to select all users whether they have images or not If they have then select the primary image. It could be simple for you but looking difficult for me.
I have 2 tables users , images
Users Table
Id | name |
1 xyz
2 abc
3 qwe
4 rty
Images Table
Id | user_id | image_path | is_primary
1 1 path 0
2 1 path 1
3 2 path 1
4 4 path 0
**Result I'm expecting**
name | image_path | is_primary
xyz | path | 1
abc | path | 1
qwe | null | 0 (this user has no image in images table)
rty | path | 0
I have no clue how to do it. It looks complicated to me as I know it could not be done with only "AND" , "Having" or "sub query".