----- Original Message ----- From: "John Mistler" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Monday, December 12, 2005 12:34 AM
Subject: Select Unique?


I have two tables 'table1', 'table2' with a matching column 'column1'. How can I return all rows from table2 where the entry for table2.column1 does not match any entries in table1.column1?

SELECT * FROM table2 WHERE table2.column1 <> table1.column1

returns all the rows, rather than the unique rows in table2 ... Any ideas?

SELECT *
FROM table2
where table2.column1 not in
(select distinct column1
from table1
where column1 not null)

The 'distinct' in the subquery is not strictly necessary but should help performance. The WHERE clause in the subquery is often omitted but really shouldn't be.

Rhino


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/198 - Release Date: 12/12/2005


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to