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 > syntax assistance delete statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-31-04, 04:45
glyndower glyndower is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
syntax assistance delete statement

Ok folks...try to hold back the laughter.

I've been away from MySql for a while and now find it neccesary to jump back in...so to that end...

DELETE FROM mlsdb.virtualdb LEFT JOIN mlsdb.mlstable ON (mlsdb.virtualdb.mlsnum = mlsdb.virtualdb.mlsnum)WHERE mlsdb.mlstable.ListID <> mlsdb.virtualdb.mlsnum

I have a db with 19 tables. I need to delete the records from the table "virtualdb" that do not have corresponding ID numbers in the table "mlstable"

I came up with the above...which obviously dosn't work, lol. any help would be appreciated.

TIA

Last edited by glyndower; 01-31-04 at 04:47.
Reply With Quote
  #2 (permalink)  
Old 01-31-04, 10:21
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
try this,

DELETE mlsdb.virtualdb FROM mlsdb.virtualdb, mlsdb.mlstable
WHERE mlsdb.mlstable.ListID = mlsdb.virtualdb.mlsnum
AND mlsdb.mlstable.ListID IS NULL

this doesn't have a shot at working unless you are running
MySQL 4.0.
Reply With Quote
  #3 (permalink)  
Old 01-31-04, 10:33
glyndower glyndower is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
nope

MySQL 3.23.54

tried it anyway, but you were right...didnt work. Thanks for the suggestion though!
Reply With Quote
  #4 (permalink)  
Old 01-31-04, 10:57
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
Then you can make a list of IDs you want to delete,

SELECT mlsdb.virtualdb.mlsnum
FROM mlsdb.virtualdb LEFT JOIN mlsdb.mlstable
ON mlsdb.mlstable.ListID = mlsdb.virtualdb.mlsnum
WHERE mlsdb.mlstable.ListID IS NULL

and delete 'em,

DELETE FROM mlsdb.virtualdb WHERE mlsdb.virtualdb.mlsnum
IN ( <your_list> )
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