Help with constructing a query
Posted: Tue Nov 26, 2002 3:20 pm
I have two tables that I'm working with in this scenario: album and album_rel. An album can have multiple "sub-albums' (or children) and can be a "sub-album" of multiple "parent" albums. The album table contains all individual-specific album information, and the album_rel table relates the albums together via two columns, child_id and parent_id, which hold the appropriate album "id" from the album table.
I'm trying to construct a query that will populate a drop-down with all available albums that are not already a child album of a given album being modified.
My query so far is as follows, and yes, I know it's not correct. I've put it here to try to better exemplify what I need:
How can I do this? 
I'm trying to construct a query that will populate a drop-down with all available albums that are not already a child album of a given album being modified.
My query so far is as follows, and yes, I know it's not correct. I've put it here to try to better exemplify what I need:
Code: Select all
$query = "SELECT a.id, a.name FROM album AS a, album_rel AS r WHERE a.id != r.child_id AND r.parent_id != '" . $rowї'id'] . "' ORDER BY a.name";