dbTalk Databases Forums  

DELETE with related table

mailing.database.mysql mailing.database.mysql


Discuss DELETE with related table in the mailing.database.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
R. Vince
 
Posts: n/a

Default DELETE with related table - 04-23-2007 , 06:45 PM






I have a table (tableA), with a data field (saved as a VARCHAR in
YYYY-MM-DD). I have a second table, tableB, which has a field with an int
field which refers to the ID of tableA (or is null). I call this field
tableB.idA

I am trying to delete rows in tableA where the date is less than a specified
value AND there is no reference to said row in tableB.

But how to specify this in SQL. I tried :

DELETE FROM tableA WHERE tableA.date <'2007-01-01' and tableB.idA!=
tableA.id;

only to get the exception Unknown table 'tableB' in where clause.

Can anyone help me out here? Thanks, R. Vince



Reply With Quote
  #2  
Old   
strawberry
 
Posts: n/a

Default Re: DELETE with related table - 04-25-2007 , 05:57 AM






On Apr 24, 12:45 am, "R. Vince" <rvince99 a t hotmail d o t com>
wrote:
Quote:
I have a table (tableA), with a data field (saved as a VARCHAR in
YYYY-MM-DD). I have a second table, tableB, which has a field with an int
field which refers to the ID of tableA (or is null). I call this field
tableB.idA

I am trying to delete rows in tableA where the date is less than a specified
value AND there is no reference to said row in tableB.

But how to specify this in SQL. I tried :

DELETE FROM tableA WHERE tableA.date <'2007-01-01' and tableB.idA!=
tableA.id;

only to get the exception Unknown table 'tableB' in where clause.

Can anyone help me out here? Thanks, R. Vince
You have to join tableB to the query.



Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.