DELETE with related table
am 24.04.2007 01:45:21 von unknown
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
Re: DELETE with related table
am 25.04.2007 12:57:22 von zac.carey
On Apr 24, 12:45 am, "R. Vince"
wrote:
> 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.