我在PostgreSQL中有这样的查询:
select p1.id, p2.id, p1.title, p2.title
from publication "p1", publication "p2"
where p1.title = p2.title and p1.id <> p2.id问题是它返回的数据比我需要的多:
id id title title
3456 5678 Ulysses Ulysses
5678 3456 Ulysses Ulysses
234, 345 Das Kapital Das Kapital
345 234 Das Kapital Das Kapital 我只需要第一行和第三行,或者第二行和第四行。
发布于 2013-03-21 02:55:39
select p1.id, p2.id
, p1.title, p2.title
from publication p1
, publication p2
where p1.title = p2.title
and p1.id < p2.id -- tie breaker
;或者使用更时髦的JOIN语法:
SELECT p1.id, p2.id
, p1.title, p2.title
FROM publication p1
JOIN publication p2 ON p1.title = p2.title
AND p1.id < p2.id -- tie breaker
;发布于 2013-03-28 13:09:47
我有一个简单的想法来实现你的场景。
select p1.id, p2.id, p1.title, p2.title , sum(p1.id + p2.id) as temp
from publication "p1", publication "p2" group by temp发布于 2018-05-31 19:30:34
select DISTINCT p1.id, p2.id, p1.title, p2.title
from publication "p1", publication "p2"
where p1.title = p2.titlehttps://stackoverflow.com/questions/15532237
复制相似问题