Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A problem with Delete Query

Status
Not open for further replies.

mouk2007

Programmer
Jul 15, 2008
11
GB
I have set up a Query formed of two tables. However when I run the delete query I get a message saying 'Specify the table containing the record you want to delete'. Could anyone please help me on how to do this. Here is the SQL:

DELETE DISTINCTROW DVDCopy.CopyNumber, DVDCopy.DVDNumber, DVDCopy.DatePurchased, Loan.DateReturned
FROM DVDCopy INNER JOIN Loan ON DVDCopy.CopyNumber = Loan.CopyNumber
WHERE (((DVDCopy.DatePurchased)<CDate(Date())-365) AND ((Loan.DateReturned) Is Not Null));

Many Thanks
 
You can only delete from one table at a time. Your use of Loan. in the delete distinctrow is the problem.

Try:
Code:
DELETE * 
FROM DVDCopy 
LEFT JOIN Loan 
ON DVDCopy.CopyNumber = Loan.CopyNumber
WHERE (((DVDCopy.DatePurchased)<CDate(Date())-365) AND ((Loan.DateReturned) Is Not Null));

Good Luck,
djj
 
Thanks for your reply. However when I pasted the SQL code you provided I still get the same message:'Specify the table containing the record you want to delete'.
 
If you are trying to delete a column of data use

UPDATE tablename SET columnname = null;

This can be done in design view but it is easier to show the code.
djj
 
Just to clarify
Code:
UPDATE tablename SET columnname = null;
does not delete a column. It sets the values in the column to NULL but the column is not deleted ... it still exists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top