Custom SQL Query: Get all posts with category id and a concated list of tags on each post

    SELECT DISTINCT
      p.ID            AS id,
      p.post_title    AS title,
      (
        SELECT group_concat(p2.guid SEPARATOR ', ')
        FROM wp_postmeta pm
        LEFT JOIN wp_posts p2 ON pm.meta_value = p2.ID
        WHERE pm.post_id = p.ID AND pm.meta_key = '_thumbnail_id' AND p2.post_type="attachment"
      )               AS image,
      (
        SELECT group_concat(pm.meta_value SEPARATOR ', ')
        FROM wp_postmeta pm
        WHERE pm.post_id = p.ID AND pm.meta_key = 'views'
      )               AS views,
      (
        SELECT group_concat(t.name SEPARATOR ', ')
        FROM wp_terms t
        LEFT JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
        LEFT JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
        WHERE tt.taxonomy = 'category' AND p.ID = tr.object_id
      )               AS category,
      (
        SELECT group_concat(t.name SEPARATOR ', ')
        FROM wp_terms t
        LEFT JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
        LEFT JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
        WHERE tt.taxonomy = 'post_tag' AND p.ID = tr.object_id
      )               AS tag
    FROM wp_posts p
    WHERE p.post_type="post" AND p.post_status="publish" AND p.ID = 10
    ORDER BY p.post_date DESC
    LIMIT 3

A result like this:

| id | title     | image     | category       | tag            |
| 10 | test post | image URL | cat, cat 2 ... | tag, tag 2 ... |

Or without this AND p.ID = 10 you could get all post with image, tags, categories:

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)