[英]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:我的 SQL 中有两个表,'post' 和 'business' 帖子中的列是:
The columns in business are业务中的列是
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.