-1

My goal is to get the following query result:

"Discussion": {
  "DiscussionID": 1,
  "Name": "Some Name",
  "Body": "Some Body",
  "Comments": [
    {
      "CommentID": 1,
      "Body: "Some Body
    }
  ]
}

I have 2 Tables: Discussions and Comments. A discussion has many comments

Discussion Table:
=================
DiscussionID
Name
Body

Comments Table:
===============
CommentID
DiscussionID
Body

How can I get all comments for a Discussion and fetch the discussion columns as well?

crispychicken
  • 2,592
  • 2
  • 33
  • 50

1 Answers1

0

This works with a join of the two tables.

Try something like this:

SELECT *
FROM   Discussion D
JOIN   Comments C
ON     C.DiscussionID = D.DiscussionID
Samuel Renold
  • 302
  • 1
  • 8