MySQL Forums
Forum List  »  Newbie

Multiple IN statements - or alternative
Posted by: Sven Delleq
Date: April 03, 2012 12:56PM

I'm grouping data like this (in the group TABLE):
ID   GROUP_NAME   GROUP_TABLE   GROUP_ITEMS
3    portfolio    cases         1,2,3,4,5,8,10,11,12

pulling data like this:
function get_group($group_name)
{
    $sql = sprintf("SELECT group_table, group_items FROM groups WHERE group_name = '%s'",
    mysql_real_escape_string($group_name));
    $group_data = $this->db->query($sql)->row();

    $sql = sprintf("SELECT * FROM %s WHERE ID IN (%s)",
    mysql_real_escape_string($group_data->group_table),
    mysql_real_escape_string($group_data->group_items));		
    $query = $this->db->query($sql)->result();	
    return $query;
}

Problem is, I have nested data like this (in the case TABLE):
ID   CASE         MEDIA_FILES
1    case one     3,4,5,6,7
2    case two     8,9
3    case three   10,11,12
4    case four    13,14,15,16,17
...
in the cases pulled, so I need to do ANOTHER nested IN statement to get the corresponding media files for each case. But how do I manage that, and get it all out at ONE result?

Options: ReplyQuote


Subject
Written By
Posted
Multiple IN statements - or alternative
April 03, 2012 12:56PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.