我有以下条件:
Table : user, owner, category, user_sub_category
inner join user.owner_id = user.id
inner join user.category_id = category.id
left join user.id = user_sub_category.lounge_id
left join user_sub_category.category_id = category.id
现在我需要在sql查询中转换它们,但我不知道我做的是否正确。到目前为止我所做的是:
SELECT * FROM db.user
inner join db.owner
on user.owner_id = owner.id
inner join db.category
on user.category_id = category.id
left join db.user_sub_category
on user.id = user_sub_category.lounge_id
and user_sub_category.category_id = category.id;
请随时纠正我。感谢
答案 0 :(得分:0)
SELECT * FROM db.user
inner join db.owner
on user.owner_id = owner.id --in condition it says user.id, but if it is owner table, then this is OK
inner join db.category
on user.category_id = category.id
left join db.user_sub_category
on user.id = user_sub_category.lounge_id
and user_sub_category.category_id = category.id;
看起来很好。