View Single Post

   
  #1 (permalink)  
Old 02-28-2008, 07:55 AM
frizzle
 
Posts: n/a
Default Delete against multiple tables + And / Or

Hi there,

a part of my music site exists of three tables:
songs -> id, artist_id, song_name
lyrics -> id, song_id, lyrics
genre -> id, song_id, genre_name

Now to delete the song (1 record), *possbile* lyrics (maybe 1 record,
maybe none), and *possible* genre-links (max unlimited records),
i use the following query:

DELETE s.*, l.*, c.*
FROM `songs` s,
`lyrics` l,
`genres` g
WHERE s.`id` = $id
AND l.`song_id` = $id
AND g.`song_id` = $id

Which works _IF_ the song also has lyrics AND genres.
Now of course, a song also has to be able to be deleted if it
hasn't got lyrics, or genres.

I tried replacing AND in the query with OR, but that kind of emptied my
songs-table ...

Any clues? Any help would be great.

Frizzle.

Reply With Quote