If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Deleting records matching a list in another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-09, 13:02
dgoadby dgoadby is offline
Registered User
 
Join Date: Mar 2009
Posts: 1
Deleting records matching a list in another table

This has been drving me nuts all day so it's time to let someone tell me I'm an idiot!

I have a list of invoices in one table and a list of invoice numbers to be deleted in another table. I want to delete invoices with numbers that are in the second table.

Now, this works:

select count(*) from purchaseinvoices as a where a.invoiceno in(select b.invoiceno from deletelist as b);

and the number is correct.

But, this does not work:

delete from purchaseinvoices as a where a.invoiceno in(select b.invoiceno from deletelist as b);

It gives me:

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where a.invoiceno in(select b.invoiceno from deletelist as b)' at line 1

purchaseinvoices is a table indexed on the field recordno. deletelist is a single column table and is not indexed.

I have seen examples of this code in various forums but it doesn't work for me. what is wrong please? I am using MySQL V5.0.45
Reply With Quote
  #2 (permalink)  
Old 03-07-09, 05:07
koandy1983 koandy1983 is offline
Registered User
 
Join Date: Jun 2008
Posts: 7
Hello!

Try this:

Code:
delete from purchaseinvoices where invoiceno in (select invoiceno from deletelist)
Reply With Quote
  #3 (permalink)  
Old 03-09-09, 00:57
bklr bklr is offline
Registered User
 
Join Date: Dec 2008
Posts: 133
try this too
delete from purchaseinvoices where exists (select * from deletelistwhere invoiceno = ter.invoiceno )
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On