Thread: unmatched
I seem to have a serious brain fart going here. I have two tables, and I want to find out which rows that are in the first do not have a match in the second. If I could create an explicit left join, I could do it by finding the rows in the second column that are NULL. Here's what I kinda have, but itjust sits there and never returns anything: select count(*) from apdf where apdf.doc_index != ondisk.doc_index; I tried the NOT IN operator (!!=), but it didn't like that at all. Is != a valid operator? Brett W. McCoy http://www.lan2wan.com/~bmccoy ----------------------------------------------------------------------- "Biology is the only science in which multiplication means the same thing as division."
On Thu, Jun 10, 1999 at 08:08:20PM -0400, Brett W. McCoy wrote: > I seem to have a serious brain fart going here. I have two tables, and > I want to find out which rows that are in the first do not have a match > in the second. If I could create an explicit left join, I could do it by > finding the rows in the second column that are NULL. Here's what I kinda > have, but itjust sits there and never returns anything: > > select count(*) from apdf > where apdf.doc_index != ondisk.doc_index; This will return every row in the second table that doesn't math the current row in the first table, for every single row in the first table. That's roughly the product of the number or rows in the two tables. What your looking for is: select count(*) from apdf where apdf.doc_index not in (select doc_index from ondisk); Ross > > I tried the NOT IN operator (!!=), but it didn't like that at all. Is != > a valid operator? > > Brett W. McCoy > http://www.lan2wan.com/~bmccoy > ----------------------------------------------------------------------- > "Biology is the only science in which multiplication means the same > thing as division." > -- Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> NSBRI Research Scientist/Programmer Computer and Information Technology Institute Rice University, 6100 S. Main St., Houston, TX 77005
"Brett W. McCoy" wrote: > I tried the NOT IN operator (!!=), but it didn't like that at all. Is != > a valid operator? Do you mean <> ? -- Chris Bitmead mailto:chris@tech.com.au http://www.techphoto.org - Photography News, Stuff that Matters
prova=> select * from prova1; a1 ----- delta alpha gamma (3 rows) prova=> select * from prova2; a2 ----- delta gamma (2 rows) prova=> select * from prova1 where a1 not in (select * from prova2); a1 ----- alpha (1 row) "Brett W. McCoy" ha scritto: > I seem to have a serious brain fart going here. I have two tables, and > I want to find out which rows that are in the first do not have a match > in the second. If I could create an explicit left join, I could do it by > finding the rows in the second column that are NULL. Here's what I kinda > have, but itjust sits there and never returns anything: > > select count(*) from apdf > where apdf.doc_index != ondisk.doc_index; > > I tried the NOT IN operator (!!=), but it didn't like that at all. Is != > a valid operator? > > Brett W. McCoy > http://www.lan2wan.com/~bmccoy > ----------------------------------------------------------------------- > "Biology is the only science in which multiplication means the same > thing as division." ______________________________________________________________ PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc 2.7.2.3 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jose'