[ENG] delete empty linked records.

[ENG] delete empty linked records.

am 19.01.2006 17:00:54 von Bob Bedford

I've a table in wich I've some datas.

This table is used by an other table to "describe" some articles. Now many
description aren't used anymore and should be deleted from the database. How
to do so ?

I've the query to show the result:
select desc.iddesc, item.iditem, item.iddesc from desc left join item on
desc.iddesc = item.iddesc where iditem is null

Every time there is no linked desc to items, then I've the desc.iddesc.

Now I've tried this:
delete from desc left join item on desc.iddesc = item.iddesc where iditem is
null
and also
delete from desc where iddesc = (select distinct iddesc from desc left join
item on desc.iddesc = item.iditem where iditem is null)

but this query doens't work....as you can guess I'm not so confortable with
mysql..., so how to do so ?

Re: [ENG] delete empty linked records.

am 19.01.2006 20:15:21 von Christian Eberhardt

Bob Bedford wrote:

> I've a table in wich I've some datas.
>
> This table is used by an other table to "describe" some articles. Now many
> description aren't used anymore and should be deleted from the database.
> How to do so ?
>
> I've the query to show the result:
> select desc.iddesc, item.iditem, item.iddesc from desc left join item on
> desc.iddesc = item.iddesc where iditem is null
>
> Every time there is no linked desc to items, then I've the desc.iddesc.
>
> Now I've tried this:
> delete from desc left join item on desc.iddesc = item.iddesc where iditem
> is null
> and also
> delete from desc where iddesc = (select distinct iddesc from desc left
> join item on desc.iddesc = item.iditem where iditem is null)
>
> but this query doens't work....as you can guess I'm not so confortable
> with mysql..., so how to do so ?

What is the error message?

The term 'desc' is part of the query language. You should put it in
backticks to qualify it for your purpose.

Re: [ENG] delete empty linked records.

am 19.01.2006 22:00:06 von Bob Bedford

>> delete from desc where iddesc = (select distinct iddesc from desc left
>> join item on desc.iddesc = item.iditem where iditem is null)
>>
>> but this query doens't work....as you can guess I'm not so confortable
>> with mysql..., so how to do so ?
>
> What is the error message?
>
> The term 'desc' is part of the query language. You should put it in
> backticks to qualify it for your purpose.

Hi,

I finally found the correct syntax:
>> delete from desc where iddesc = (select distinct iddesc from desc left
>> join item on desc.iddesc = item.iditem where iditem is null)
becomes
delete from desc using desc left join item on desc.iddesc = item.iditem wher
iditem is null.

The correct query takes with a delete is with "using" for the join table.

Bob