Jump to content

JOIN Question


supaflyfrank

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/62566-join-question/
Share on other sites

$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...

Link to comment
https://forums.phpfreaks.com/topic/62566-join-question/#findComment-311673
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.