What is the difference between these queries

From: salah jubeh <s_jubeh(at)yahoo(dot)com>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: What is the difference between these queries
Date: 2011-04-12 09:47:12
Message-ID: 828595.84001.qm@web161519.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Query1
-- the first select return 10 rows
SELECT a, b
FROM table1 LEFT JOIN table2 on (table1_id = tabl2_id)
Where table1_id NOT IN (SELECT DISTINCT table1_id FROM table3)
EXCEPT
-- this select return 5 rows
SELECT a, b
FROM table1 LEFT JOIN table2 on (table1_id = tabl2_id)
Where table1_id NOT IN (SELECT DISTINCT table1_id FROM table3)
and b ~* 'pattern'
-- the result is 5 rows

Query2
--this select return 3 rows
SELECT a, b
FROM table1 LEFT JOIN table2 on (table1_id = tabl2_id)
Where table1_id NOT IN (SELECT DISTINCT table1_id FROM table3)
and b !~* 'pattern'

Why query1 and query2 return different set. note that query two return a subset
of query1

Responses

Browse pgsql-general by date

  From Date Subject
Next Message AI Rumman 2011-04-12 10:06:24 pg_connect connection problem
Previous Message Sven Haag 2011-04-12 07:53:24 Multiple Results with crosstab function