The syntax to do this in Transact SQL would be,

 Delete From notes where location in (select rowid from locations where map
= @MapID)
 Delete From Locations Where Map = @MapID
 Delete From Maps Where RowID = @MapID

I dont imagine that MySQL would be that different, although I have a nagging
feeling that MySQL doesnt suppport nested queries.

BTW, "@MapID" in the above code is a variable with ID of the map you want
deleted.

Jason

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: 05 July 1979 22:38
To: [EMAIL PROTECTED]
Subject: [PHP] mysql fun! JOIN me ...


Question 1: is there a good explination online of how to use the JOIN
function in mysql? I've looked at the documentation:

http://www.mysql.com/doc/J/O/JOIN.html

but it's to confusing. It doesn't exactly what you are joining or why you
might want to do that ... I think JOIN is what I need, here is the problem:




So I have some tables:


create table maps
(
rowid INT(10) AUTO_INCREMENT PRIMARY KEY NOT NULL
);

create table locations
(
map INT(10),  #map rowid
rowid INT(10) AUTO_INCREMENT PRIMARY KEY NOT NULL
);

create table notes
(
location INT(10), ## location rowid
rowid INT(10) AUTO_INCREMENT PRIMARY KEY NOT NULL
);



Each map has many locations and each location has many notes ...

I want to delete the map, all of it's locations and all of the locations
notes.

clearing the maps and locations is easy:

$sql = "DELETE FROM maps WHERE (rowid='$mapid')";
$result = mysql_query($sql);

$sql = "DELETE FROM locations WHERE (map='$mapid')";
$result = mysql_query($sql);


but how to get rid of those notes?


I'm thinking of sending all of the location rowid(s) to an array then using
that array to delete the notes ... but I think this JOIN thing might let me
do it all with one query.

Can any of you kind folks help me here?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to