Board index » delphi » Select all records except those in another table

Select all records except those in another table

I have two tables A and B (this one could be a SQL as well).

Table A is the detail in a master/detail join (with another table other than
B).

Table A and Table B have a common field (CommonFieldA, CommonFieldB).

I want to show all records of Table B with a value of the field
'CommonFieldB'
different from those of 'CommonFieldA' appearing in Table A. That is, if
'CommonField' is the
serial number of my articles, I want to show all 'articles' (Table B) except
those that have already
appeared in one of the fields of Table A (which contains sales), that is the
result of a master/detail join.

Thanks in advance.

Antonio.

 

Re:Select all records except those in another table


There's probably a better way to do this, but here's what I've come up with
off the top of my head....

Select b.*
from TableB b
Outer Join TableA a
where a.CommonField Is Null

-Dell

Re:Select all records except those in another table


SELECT B.* FROM TABLEB B
RIGHT OUTER JOIN TABLEA A
WHERE A.COMMONFIELD IS NULL

SELECT B.* FROM TABLEB
WHERE B.COMMONFIELD NOT IN (SELECT COMMONFIELD FROM TABLEA)

--
Bill

Other Threads