mysql - select from 3 tables with null values -
i have 3 tables
- users columns user name, user id
- groups columns group name,group id
- users_group columns user id, group id
the user group contains relation between users , groups.
i want select users , groups user names , group names togother. want users dont have group return value of group name null
how create such sql in mysql
you need left join
as
select u.username, g.group_name users u left join users_group ug on ug.user_id = u.user_id left join groups g on g.group_id = ug.group_id
Comments
Post a Comment