Click to See Complete Forum and Search --> : sql; want to delete every record from one table, if PK listed in another table


cjard
October 11th, 2004, 12:50 PM
hi

i have two tables, one has 120 000 products in, the other, a smaller table of 4000 products that need to be deleted from the big table. the primary key is formed from 2 numerical elemnts; the barcode and the pipcode.
how do i form a delete query that will do this? i tried the following:

DELETE bigTable.*
FROM bigTable
INNER JOIN smallTable ON (bigTable.BarCode = smallTable.barToDelete) AND (bigTable.BarpipCode = smallTable.pipToDelete);

If i change it to a select query, i can see the records i want to delete (this is in ms access), but the delete query merely says "cant delete from tables"
there are no relationships defined

cjard
October 11th, 2004, 01:04 PM
DELETE bigtable.*
FROM bigtable
WHERE EXISTS (SELECT barToDelete
FROM smalltable
WHERE smalltable.barToDelete = bigtable.BarCode
AND smalltable.pipToDelete = bigtable.BarpipCode
);