Ken Hill wrote:
I need some help with a bit of SQL. I have two tables. I want to find
records in one table that don't match records in another table based
on a common column in the two tables. Both tables have a column named
'key100'. I was trying something like:
SELECT count(*)
FROM table1, table2
WHERE (table1.key100 != table2.key100);
But the query is very slow and I finally just cancel it. Any help is
very much appreciated.
-Ken
Maybe you could use a NOT EXISTS subquery, as in
SELECT count(*) from table1
WHERE NOT EXISTS(SELECT count(*) from table2 WHERE table1.key100
=table2.key100)
which gives you the number of records in table1 without corresponding
records in table2.
That kind of query is quite fast, if there exists an index on table2.key100
hth
P.Jacquot
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster