Re: Non Matching Records in Two Tables
| От | Patrick JACQUOT |
|---|---|
| Тема | Re: Non Matching Records in Two Tables |
| Дата | |
| Msg-id | 43EB048B.6050203@anpe.fr обсуждение исходный текст |
| Ответ на | Non Matching Records in Two Tables (Ken Hill <ken@scottshill.com>) |
| Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: