Hi!

On Oct 22, Moshe Gurvich wrote:
> yeah, noticed it after clicked send..
> 
> let's say i upgrade to MySQL 4.0 and run this query:
> 
> DELETE FROM tasks as t_child LEFT JOIN tasks as t_parent ON
> t_child.parent_id=t_parent.task_id
> WHERE t_parent.task_id IS NULL
> 
> 
> will this work?

no.

> meaning it will delete records from 1st mentioned table in JOIN structure?

Why waste the time guessing ? It's in the manual.
Online manual is for 4.0, so you need not even download mysql-4.0
to read the manual.

See my example -
you have to put tables to delete from between DELETE and FROM :

 DELETE followups FROM followups LEFT JOIN tasks USING(task_id) WHERE
 tasks.task_id IS NULL;

There can be several tables there - it's multi-table delete, after all
:-)

Access syntax is supported too:

 DELETE followups.* FROM followups LEFT JOIN tasks USING(task_id) WHERE
 tasks.task_id IS NULL;


> Hi!
> 
> On Oct 22, Moshe Gurvich wrote:
> > thank you very much;
> >
> > i'm using right now v3.23 as recommended for production servers, but
> > anyway..
> >
> > now, using the way you suggested, will this work:
> >
> > DELETE FROM tasks
> > FROM tasks as t_child LEFT JOIN tasks as t_parent ON
> > t_child.parent_id=t_parent.task_id
> > WHERE t_parent.task_id IS NULL
> >
> > thanx :)
> 
> It won't work - note two FROM clauses.
> 
> Multi-table deletes are available in 4.0 only.
> In 3.23, I'm afraid, you have to do it in application :-(
> 
> > On Oct 22, Moshe Gurvich wrote:
> > > so what's the remedy?
> > > how to do this task in MySQL without using subselects?
> > >
> > > > delete from followups where task_id not in (select task_id from tasks)
> > > >
> >
> > Multi-table deletes (MySQL 4.0.0+)
> >
> > DELETE followups FROM followups LEFT JOIN tasks USING(task_id) WHERE
> > tasks.task_id IS NULL;
> >
> > Regards,
> > Sergei
> >
Regards,
Sergei

-- 
MySQL Development Team
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /   Sergei Golubchik <[EMAIL PROTECTED]>
 / /|_/ / // /\ \/ /_/ / /__  MySQL AB, http://www.mysql.com/
/_/  /_/\_, /___/\___\_\___/  Osnabrueck, Germany
       <___/

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to