左连接排序与NULL值

时间:2022-09-25 12:28:15

i need to sort left join by company id so that categories selected by companies will appear first.

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

My category table is

我的分类表是

左连接排序与NULL值

company_category table is

company_category表是

左连接排序与NULL值

expected result should be

预期的结果应该是

左连接排序与NULL值

1 个解决方案

#1


0  

I am supposing below query is best solution rather than using union to show company categories on top.

我认为以下查询是最佳解决方案,而不是使用union来显示公司类别。

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

#1


0  

I am supposing below query is best solution rather than using union to show company categories on top.

我认为以下查询是最佳解决方案,而不是使用union来显示公司类别。

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