davidtheo Posted November 5, 2010 Share Posted November 5, 2010 Hi All, I would like to know is there a way I can get chained records from MySQL in a single query. Table Id Parent_id Number Data id parent_id number 1 null 1 2 1 3 4 2 10 6 3 100 I need a query that will get all records where parent_id = id where I what the records where number = 1; Can anyone help me? Quote Link to comment https://forums.phpfreaks.com/topic/217835-query-that-gets-chained-records/ Share on other sites More sharing options...
fenway Posted November 9, 2010 Share Posted November 9, 2010 You mean like a "join"? Quote Link to comment https://forums.phpfreaks.com/topic/217835-query-that-gets-chained-records/#findComment-1132256 Share on other sites More sharing options...
ManiacDan Posted November 9, 2010 Share Posted November 9, 2010 If you have a self-referencing table like this, you can actually join to itself: SELECT * FROM table AS parent_table JOIN table AS child_table ON parent_table.id = child_table.parent_id WHERE parent_table.number = 1 -Dan Quote Link to comment https://forums.phpfreaks.com/topic/217835-query-that-gets-chained-records/#findComment-1132331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.