
我最喜欢查理的答案,但是我不确定Postges是否具有TOP / LIMIT函数,因此这是一种不需要的替代解决方案(但假设sub_table具有一个名为“
id”的主键):
SELECt * FROM main_table m LEFT OUTER JOIN sub_table s ON s.main_table_id = m.idWHERe s.id IS NULL OR s.id IN ( SELECt MAX(id) FROM sub_table GROUP BY main_table_id)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)