我有两张桌子,即宿舍和评级。如何通过两个表的评级显示记录顺序。我可以请求您对此进行一些了解
|------------------------------|------------------------------------|
| hotel table is | rating table is |
|------------------------------|------------------------------------|
|post_id | user_id | hostel |r_id | user_id | post_id | rating |
| 1 | 2 | xyz | 2 | 2 | 1 | 5 |
| 3 | 4 | abc | 4 | 4 | 1 | 3 |
| 5 | 6 | ijk | 5 | 6 | 6 | 4 |
| 6 | 7 | pqr | 6 | 7 | 6 | 5 |
| 8 | 8 | mno | 7 | 8 | 5 | 5 |
---------------------------------------------------------------------
答案 0 :(得分:1)
尝试以下查询:
$query = "SELECT * FROM hotel inner join rating ON hotel.post_id = rating.post_id ORDER BY rating.rating DESC";
答案 1 :(得分:0)
这样的事情:
select *
from hotel h join rating r
using (post_id, user_id)
order by rating desc;
答案 2 :(得分:0)
$query = "SELECT * FROM hotel_table
LEFT JOIN rating_table ON hotel_table.post_id = rating_table.post_id
ORDER BY rating_table.rating DESC";
试试这个