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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.