Re: Query regarding Intersect clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ajit Pradnyavant <ajit(dot)pradnyavant(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Query regarding Intersect clause
Date: 2012-05-16 15:03:26
Message-ID: 25968.1337180606@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ajit Pradnyavant <ajit(dot)pradnyavant(at)gmail(dot)com> writes:
> I think result of INTERSECT ALL query may be :

> Srno Name
> 1 Aaaa
> 1 Aaaa

> Because intersect all clause returns the duplicate values.

No; per the documentation at
http://www.postgresql.org/docs/9.1/static/sql-select.html#SQL-INTERSECT

The result of INTERSECT does not contain any duplicate rows unless the
ALL option is specified. With ALL, a row that has m duplicates in the
left table and n duplicates in the right table will appear min(m,n)
times in the result set.

So a single instance of Aaaa is appropriate for your example. (This
definition is per the SQL standard btw.)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-05-16 15:08:44 Re: Slow queries when functions are inlined
Previous Message Evan Martin 2012-05-16 14:48:03 Re: Slow queries when functions are inlined