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.
我有两张桌子
现在,我想在一个限制为 20 的页面上显示产品,问题是首先我想在按 offer_id desc 排列的报价表上显示所有产品,然后在产品表上显示产品,除了报价表上的那些 20限制。
提前谢谢大家
您只需要一个外连接,然后按降序排序offer_id(MySQL 将放置NULL值,例如从没有匹配记录的外连接中获取的值,最后以这样的顺序排列):
offer_id
NULL
SELECT Products.* FROM Products LEFT JOIN Offers USING (prod_id) ORDER BY Offers.offer_id DESC LIMIT 20
在sqlfiddle上查看。