FROM t1 JOIN t2 ON t1.id = t2.id
)
- Original Message -
From: "Vincent Hikida" <[EMAIL PROTECTED]>
To: "peter pilsl" <[EMAIL PROTECTED]>; "PostgreSQL List"
<[EMAIL PROTECTED]>
Sent: Saturday, December 18, 2004 12:40 AM
S
ecember 15, 2004 1:03 PM
Subject: [GENERAL] UNION with more restrictive DISTINCT
I'd like to UNION two queries but the distinct-criteria for UNION should
not be all columns in the queries, but only one.
example. two tables:
test=# select id,name from t1;
id | name
+--
1 | bob
2 | mik
You probably want something more like:
SELECT DISTINCT ON (id), * FROM
(
UNION ALL
);
The fact that UNION sorts at all is a side-effect of the
implementation. The distinct part is part of the SQL spec. Use UNION
ALL to get all the rows and then DISTINCT ON to do what you actually
want..
I'd like to UNION two queries but the distinct-criteria for UNION should
not be all columns in the queries, but only one.
example. two tables:
test=# select id,name from t1;
id | name
+--
1 | bob
2 | mike
(2 rows)
test=# select id,name from t2;
id | name
+-
1 | bob