从具有多个连接条件的另一个表中获取值



我想从表2中找到值。在表2上,它有多个连接条件。它总是得到表2中的所有条件。表1有重复记录,我不希望是

t1

<表类>idtrx_idtbody><<tr>1trx12342trx56783trx43214trx8765

你说表1有重复的记录,但表2有。根据你的表结构。

这对你很有帮助

SELECT distinct a.id, a.trx_id, b.status
FROM
dbo.t1 a
LEFT JOIN
dbo.t2 b on a.trx_id = b.trx_id
WHERE b.status = 'success';

结果将显示

id | trx_id | status
1  |trx1234 | success

最新更新