2013-04-02 53 views
0

我需要按公司ID排序左连接,以便公司选择的类别将首先出现。左连接用NULL值排序

我的类别表是

enter image description here

company_category表

enter image description here

预期的结果应该是

enter image description here

回答

0

我认为下面的查询是最好的解决方案,而不是使用联盟来显示公司类别。

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