gpt4 book ai didi

mysql - 我如何在左连接中排序?

转载 作者:太空宇宙 更新时间:2023-11-03 10:57:41 25 4
gpt4 key购买 nike

在很多情况下,人们需要在左连接中进行排序,我目前正在尝试从一组用户中找到最新的工作列表,不幸的是,我无法运行它,我目前拥有的是:

select * from `Profiles`
left join (select isPrimary, startDate, Orgs.`orgName`, Orgs.`title` from
Orgs order by isPrimary ) job on
`Profiles`.`ID` = Orgs.`ID`
group by `Profiles`.`ID`
limit 0,2

我觉得我可能离这里很近,但是有人可以提供一些见解吗?

最佳答案

这里为什么要用subselect?为什么不只是:

SELECT p.*, o.isPrimary, o.startDate, o.orgname, o.title FROM `Profiles` AS p
LEFT JOIN `Orgs` AS o
ON p.ID = o.ID
GROUP BY p.ID
ORDER BY p.ID, o.isPrimary
LIMIT 0,2

关于mysql - 我如何在左连接中排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18833654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com