如何在表中选择并按另一个表排序的结果 [英] How to select in table and results sorted by another table
本文介绍了如何在表中选择并按另一个表排序的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建符合我要求的 mysql 语句.2个表如下
Hi I was trying to create mysql statement that fit to my requirement. 2 tables as below
postTable
post_id | from_id
100 | 1
100 | 2
100 | 3
100 | 4
100 | 5
爱情表
post | uid
1 | 1
100 | 3
100 | 4
100 | 5
5 | 6
我想 select from_id from postTable where post_id=100 order by
//uid 首先在 loveTable 中有 post =100.
I want to select from_id from postTable where post_id=100 order by
//uid that have post =100 in loveTable firstly.
期待结果
from_id
3
4
5
1
2
你能告诉我什么是正确的选择语句吗?
Can you please advise me what is the right select statement?
推荐答案
select p.from_id
from postTable p left join lovetable o on p.from_id=o.uid
and o.post=100
where p.post_id=100
order by o.uid is not null desc,p.from_id
这篇关于如何在表中选择并按另一个表排序的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文