This question already has an answer here:

I am trying to output the post details, as well as the Comments in wordpress’s database.
Using this code

SELECT ID,post_title, wp_comments.comment_author, wp_comments.comment_author_email, wp_comments.comment_content
FROM wp_posts
INNER JOIN wp_comments ON wp_posts.id=wp_comments.comment_post_id
WHERE post_status = "publish"

So far I am getting individual rows like this:

| ID  |Title       |comment_author| comment_content        |
|----------------------------------------------------------|
| 117 |HURT LOCKER | Rob          | blah blah              |
| 117 |HURT LOCKER | Dave         | pow wow wow            |

but what i would like is (ie one line per post)

| ID  |Title       |auth1| comment1  |auth2 |comment2   |auth3 etc..
|-------------------------------------------------------|
| 117 |HURT LOCKER | Rob | blah blah |Dave  |Pow wow wow|

For a similar query I used IF statements but wont work here as I’m not sure how to differentiate between the different comments to move into columns…Could someone advise on how to separate the different values into columns within the SELECT statement?

Read more here: SQL Select Statement to put multiple results into separate columns [duplicate]


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , , , , ,

Wordpress related questions and answers: