我有一个简单连接的以下查询。 对于table_A中的每一行,有几行在table_B中匹配。我只想获得其中一场比赛(哪一场比赛并不重要)。我该怎么做?
SELECT a.id, b.something
FROM table_A a
LEFT JOIN table_B b ON a.Id = b.something
我正在使用teradata。
答案 0 :(得分:2)
假设您的结果在每列中都显示完全重复,您只需将DISTINCT添加到您的select子句中
SELECT DISTINCT a.id, b.something FROM table_A a LEFT JOIN table_B b ON a.Id = b.something
答案 1 :(得分:0)
如果您执行下面的GROUP BY
,那么每个a.id只会获得一行:
SELECT a.id, max(b.something)
FROM table_A a
LEFT JOIN table_B b ON a.Id = b.something
group by a.id
答案 2 :(得分:0)
您是否尝试过sample
:
SELECT a.id, b.something
FROM table_A a
LEFT JOIN table_B b ON a.Id = b.something
GROUP BY a.id
SAMPLE 1 ;
答案 3 :(得分:0)
添加
GROUP BY 1, 2
到您的查询