简体   繁体   中英

How do you fetch records from a table with order of another table using foreign key

I have two tables in my SQL, 'post' and 'business' The columns in the post are:

  • Post_ID
  • Content
  • Img
  • Business_ID

The columns in business are

  • Business_ID
  • Business name
  • Business rating

What I want is I want the posts which are posted by businesses with high business rating come first before others, please is there a way to fetch the posts with order of business rating???

To order results of posts with associated business rating you need a join query

select p.*
from posts as p
join business as b on b.business_id = p.business_id
order by b.business_rating desc

order by查询排列评级使用order by

select * from posts,business order by business_rating where posts.business_ID=business.business_ID;

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