please notice that in 2nd query i sent, there's same table linked twice,
because i need to link tree-like records.

how do i delete records from 1st table and not 2nd if they have same real
name?

like this:

DELETE 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



-----Original Message-----
From: Sergei Golubchik [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 22, 2001 3:52 PM
To: Moshe Gurvich
Cc: [EMAIL PROTECTED]
Subject: Re: how to sub-select?..


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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.281 / Virus Database: 149 - Release Date: 9/18/2001



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