简体   繁体   中英

How can I convert this condition to query

I have a condition below:

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

And now I need to convert them in sql query but I don't know if what I did is right. What I've done so far is:

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;

Please feel free to correct me. Thanks

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;

It looks fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM