在查询表中只提供一次唯一条目的SQL查询

问题描述 投票:-1回答:1

基本上我有2个表1或2,如下图所示。我想联合这两个表,但值列应该只在第一个条目中反映一次。

我有关于SQL的基本知识,但请指导我如何按照上面提到的标准获得所需的输出。

enter image description here

sql
1个回答
1
投票

你可以用left join做到这一点:

select t2.*, t1.value
from table2 t2 left join
     table1 t1
     on t1.code = t2.code and t2.type = 'A';
© www.soinside.com 2019 - 2024. All rights reserved.