4
左联接的前1名
给定下面的查询,dps_markers中可能有多个具有相同标记键的行,但我们只想与第一个连接。如果我执行此查询并删除前1个和ORDER BY,则会得到mbg.marker_value的值,但按原样运行,它将始终返回null SELECT u.id, mbg.marker_value FROM dps_user u LEFT JOIN (SELECT TOP 1 m.marker_value, um.profile_id FROM dps_usr_markers um (NOLOCK) INNER JOIN dps_markers m (NOLOCK) ON m.marker_id= um.marker_id AND m.marker_key = 'moneyBackGuaranteeLength' ORDER BY m.creation_date ) MBG ON MBG.profile_id=u.id WHERE u.id = 'u162231993'