Re: [GENERAL] UNION with more restrictive DISTINCT

2004-12-19 Thread Vincent Hikida
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

Re: [GENERAL] UNION with more restrictive DISTINCT

2004-12-18 Thread Vincent Hikida
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

Re: [GENERAL] UNION with more restrictive DISTINCT

2004-12-15 Thread Martijn van Oosterhout
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..

[GENERAL] UNION with more restrictive DISTINCT

2004-12-15 Thread peter pilsl
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