Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要按公司 ID 对左连接进行排序,以便公司选择的类别首先出现。
我的类别表是
company_category 表是
预期结果应该是
我认为下面的查询是最好的解决方案,而不是使用联合在顶部显示公司类别。
SELECT * FROM category c LEFT JOIN company_category cc ON c.category_id=cc.category_id AND cc.company_id=1 ORDER BY cc.company_id DESC