UNION or OR / INTERSECT or AND ?

From: "David W" <willou(dot)d(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: UNION or OR / INTERSECT or AND ?
Date: 2006-02-07 14:04:06
Message-ID: 1139321046.697952.264710@g44g2000cwa.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

do i have to prefered to use UNION and INTERSECT or is it better with
OR and AND ?

Query example :

1. OR

SELECT a.designation, m.label FROM article a JOIN manufacturer m ON
m.id = a.manufacturer_id
WHERE a.designation || m.label ILIKE '%elec%'
OR a.designation || m.label ILIKE '%compa%'
OR a.designation || m.label ILIKE '%xs%'

2. UNION

SELECT a.designation, m.label FROM article a JOIN manufacturer m ON
m.id = a.manufacturer_id WHERE a.designation || m.label ILIKE '%elec%'
UNION
SELECT a.designation, m.label FROM article a JOIN manufacturer m ON
m.id = a.manufacturer_id WHERE a.designation || m.label ILIKE '%compa%'
UNION
SELECT a.designation, m.label FROM article a JOIN manufacturer m ON
m.id = a.manufacturer_id WHERE a.designation || m.label ILIKE '%xs%'

My actual database, is too small to see a real difference. That's why i
prefered to ask this newsgroup.

Thanks for your support,
David "Willou".
http://www.willou.net.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2006-02-07 14:23:35 Re: Installation of PostGIS
Previous Message gwx cathy 2006-02-07 14:00:16 Installation of PostGIS