supaflyfrank Posted July 30, 2007 Share Posted July 30, 2007 Hello I am new to SQL/MySql What I having a problem with is a 1 to many relationship. First I want to be able to display all additional comments that is attached to 1 comment. For Example ------Comment Table------ Primary ID Comment 1 Hey 2 Yo ..... ...... ------Additional Comment--- Foreign ID AddComment 1 Hey Who 1 Who is he talking to 1 This is stupid 2 Who you Yoing? ..... .................. The Join Should be ---------Example Results------- Hey - Hey Who Who is he talking to This is stupid I read about joins but dont know how to achieve this. My ultimate goal is through a single sql query statement to list all comments with all of their additional comments unique to each comment if you understand. For Example ---------Example Results------- Hey - Hey Who Who is he talking to This is stupid Yo - Who You Yoeing Any help will be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/62566-join-question/ Share on other sites More sharing options...
Wildbug Posted July 31, 2007 Share Posted July 31, 2007 SELECT * FROM table1 JOIN table2 ON table1.id=table2.id ORDER BY table2.id,table2.date; I made up the table/column names, but you get the idea (I hope). Quote Link to comment https://forums.phpfreaks.com/topic/62566-join-question/#findComment-311519 Share on other sites More sharing options...
clearstatcache Posted July 31, 2007 Share Posted July 31, 2007 $query = " select t1.Comment, t2.AddComment from CommentTable as t1 left join AdditionalComment as t2 on t1.PrimaryKey = t2.ForeignKey order by t1.Comment, t2.AddComment "; bwt trying ds one... Quote Link to comment https://forums.phpfreaks.com/topic/62566-join-question/#findComment-311673 Share on other sites More sharing options...
DeadEvil Posted July 31, 2007 Share Posted July 31, 2007 $query = "SELECT primary_ID, comment, AddComment FROM comment " . "LEFT JOIN Additional_Comment ON primary_ID = Foreign_ID " . "ORDER BY primary_ID DESC"; $result = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/62566-join-question/#findComment-311684 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.