Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.