Currently I've got the following query:
SELECT c.Permlink
, c.ParentID
, c.AuthorID
, u.Username AS Author
, c.Title
, c.Body
, c.Metadata
, c.PostTime
, v.VoterID
, v.VoteValue
, voterID.Username AS Voter
FROM comments c
LEFT
JOIN deleted_comments d
ON c.Permlink = d.Permlink
LEFT
JOIN votes v
ON c.Permlink = v.Permlink
JOIN users u
ON u.id = c.AuthorID
LEFT
JOIN users As voterID
ON voterID.ID = v.VoterID
WHERE c.AuthorID = 88077
AND c.ParentID IS NULL
AND d.Permlink IS NULL
And I get the following result:
[
{
"Permlink" : 3,
"ParentID" : null,
"AuthorID" : 88077,
"Author" : "rishi556",
"Title" : "",
"Body" : "foxon",
"Metadata" : "{}",
"PostTime" : 1589475759,
"VoterID" : 88077,
"VoteValue" : 1,
"Voter" : "rishi556"
},
{
"Permlink" : 5,
"ParentID" : null,
"AuthorID" : 88077,
"Author" : "rishi556",
"Title" : "",
"Body" : "foxonier?",
"Metadata" : "{}",
"PostTime" : 1589475774,
"VoterID" : 1278255,
"VoteValue" : 1,
"Voter" : "gamer556"
},
{
"Permlink" : 5,
"ParentID" : null,
"AuthorID" : 88077,
"Author" : "rishi556",
"Title" : "",
"Body" : "foxonier?",
"Metadata" : "{}",
"PostTime" : 1589475774,
"VoterID" : 88077,
"VoteValue" : 1,
"Voter" : "rishi556"
},
{
"Permlink" : 9,
"ParentID" : null,
"AuthorID" : 88077,
"Author" : "rishi556",
"Title" : "",
"Body" : "does this work?",
"Metadata" : "{}",
"PostTime" : 1589475858,
"VoterID" : null,
"VoteValue" : null,
"Voter" : null
}
]
To reduce repetition, I would like the data in VoteID
, VoteValue
, Voter
to be put into an array, so something like this, using the Permlink : 5 as the example:
[
{
"Permlink" : 5,
"ParentID" : null,
"AuthorID" : 88077,
"Author" : "rishi556",
"Title" : "",
"Body" : "foxonier?",
"Metadata" : "{}",
"PostTime" : 1589475774,
"Votes" : [{"VoterID" : 1278255,"VoteValue" : 1,"Voter" : "gamer556"},{"VoterID" : 88077, "VoteValue" : 1,"Voter" : "rishi556"} ]
}
]
And for those with null in their votes(meaning that it hasn't received votes yet), it should just be an empty array.
What would I need to add to the query to do that? Or would it not be possible with a change to the query and I'd need to manipulate in my code?