Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:14:29+00:00 2026-06-18T08:14:29+00:00

Table 1 | ID | Post_Name | Post_Status | Parent_ID | Post_Content | Post_Type

  • 0
Table 1
| ID | Post_Name  | Post_Status | Parent_ID | Post_Content | Post_Type |
+----+------------+-------------+-----------+--------------+-----------+
| 1  | John Sample| publish     | 0         | Content Text | person    |
| 2  |            | inherit     | 1         | image1.jpg   | attachment|
| 3  |            | inherit     | 1         | image2.jpg   | attachment|
| 4  |            | inherit     | 1         | image3.jpg   | attachment|
| 5  | Mark Sample| publish     | 0         | Mark  Text   | person    |
| 6  |            | inherit     | 5         | image1.jpg   | attachment|
| 7  |            | inherit     | 5         | image2.jpg   | attachment|
| 8  |            | inherit     | 5         | image3.jpg   | attachment|

Table 2
| meta_id | post_id  |    meta_key    |      meta_value       |
+---------+----------+----------------+-----------------------+
|   1     |    1     |  Address       | Sample Street,Country |
|   2     |    1     |  Phone         | 10000000000000        |
|   3     |    1     |  Sex           | Male                  |
|   4     |    1     |  Primary pic   | 2                     |
|   5     |    2     |  Thumbnail     | John_thumbnail.jpg    |
|   6     |    2     |  meta_data     | data_data_data        |
|   7     |    5     |  Address       | Mark Street,Country   |
|   8     |    5     |  Phone         | 20000000000000        |
|   9     |    5     |  Sex           | Male                  |
|   10    |    5     |  Primary pic   | 6                     |
|   11    |    6     |  Thumbnail     | Mark_thumbnail.jpg    |
|   12    |    6     |  meta_data     | data_data_data        |

I would like to display like this

Name: John Sample
Comment: Content Text
Address: Sample Street, Florida
Phone: 10101010101010
Sex: Male
Thumbnail: John_thumbail.jpg
Photo: images1.jpg, images2.jpg, images3.jpg

Name: Mark Sample
Comment: Mark Text
Address: Mark Street, Florida
Phone: 20101010101010
Sex: Male
Thumbnail: Mark_thumbail.jpg
Photo: images1.jpg, images2.jpg, images3.jpg

see how the thumbnail links

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:14:30+00:00Added an answer on June 18, 2026 at 8:14 am

    Try this:

    SELECT
      t.Post_Name AS Name,
      MAX(CASE WHEN t2.meta_key = 'Address' THEN t2.meta_value END) AS 'Address',
      MAX(CASE WHEN t2.meta_key = 'Phone' THEN t2.meta_value END) AS 'Phone',
      MAX(CASE WHEN t2.meta_key = 'Sex' THEN t2.meta_value END) AS 'Sex',
      GROUP_CONCAT(DISTINCT p.Post_Content  SEPARATOR ',') AS Photo
    FROM Table1 p
    INNER JOIN table1 t ON p.parent_ID = t.ID
    INNER JOIN Table2 t2 ON t.Id = t2.post_id
    GROUP BY p.Post_Name;
    

    SQL Fiddle Demo

    This will give you:

    |        NAME |               ADDRESS |          PHONE |  SEX |                            PHOTO |
    --------------------------------------------------------------------------------------------------
    | John Sample | Sample Street,Country | 10000000000000 | Male | image3.jpg,image2.jpg,image1.jpg |
    

    Then using PHP, you can display them the way you want.


    Update

    If you want to display the value of user comment as comment, you can do this:

    SELECT
      t.Post_Name AS Name,
      MAX(CASE WHEN t2.meta_key = 'Address' THEN t2.meta_value END) AS 'Address',
      MAX(CASE WHEN t2.meta_key = 'Phone' THEN t2.meta_value END) AS 'Phone',
      MAX(CASE WHEN t2.meta_key = 'Sex' THEN t2.meta_value END) AS 'Sex',
      GROUP_CONCAT(DISTINCT p.Post_Content  SEPARATOR ',') AS Photo,
      GROUP_CONCAT(DISTINCT t.post_Content) comment
    FROM Table1 p
    INNER JOIN table1 t ON p.parent_ID = t.ID
    INNER JOIN Table2 t2 ON t.Id = t2.post_id
    GROUP BY p.Post_Name;
    

    Updated SQL fiddle Demo


    Update2:

    Based on the updated sample data:

    SELECT
      p.Post_Name AS Name,
      MAX(CASE WHEN t.meta_key = 'Address' THEN t.meta_value END) AS 'Address',
      MAX(CASE WHEN t.meta_key = 'Phone' THEN t.meta_value END) AS 'Phone',
      MAX(CASE WHEN t.meta_key = 'Sex' THEN t.meta_value END) AS 'Sex',
      GROUP_CONCAT(DISTINCT c.Post_Content  SEPARATOR ',') AS Photo,
      GROUP_CONCAT(DISTINCT p.post_Content) comment
    FROM
    (
      SELECT *
      FROM Table1 
      WHERE parent_id = 0
    ) AS p
    INNER JOIN table1 AS c ON p.ID      = c.parent_ID
    INNER JOIN table2 AS t ON t.post_id = p.id
    GROUP BY p.post_Name;
    

    SQL Fiddle Demo

    This will give you:

    |        NAME |               ADDRESS |          PHONE |  SEX |                            PHOTO |      COMMENT |
    -----------------------------------------------------------------------------------------------------------------
    | John Sample | Sample Street,Country | 10000000000000 | Male | image2.jpg,image1.jpg,image3.jpg | Content Text |
    | Mark Sample |   Mark Street,Country | 20000000000000 | Male | image3.jpg,image1.jpg,image2.jpg |   Mark  Text |
    

    Update 2

    For the updated data, try this:

    SELECT 
      t1.*,
      t2.meta_value AS 'Thumbnail'
    FROM
    (
      SELECT
        p.Post_Name AS Name,
        MAX(CASE WHEN t.meta_key = 'Address' THEN t.meta_value END) AS 'Address',
        MAX(CASE WHEN t.meta_key = 'Phone' THEN t.meta_value END) AS 'Phone',
        MAX(CASE WHEN t.meta_key = 'Sex' THEN t.meta_value END) AS 'Sex',
        MAX(CASE WHEN t.meta_key = 'Primary pic' THEN t.meta_value END) AS 'Primary_pic',
        GROUP_CONCAT(DISTINCT c.Post_Content  SEPARATOR ',') AS Photo,
        GROUP_CONCAT(DISTINCT p.post_Content) comment
      FROM
      (
        SELECT *
        FROM Table1 
        WHERE parent_id = 0
      ) AS p
      INNER JOIN table1 AS c ON p.ID      = c.parent_ID
      INNER JOIN table2 AS t ON t.post_id = p.id
      GROUP BY p.post_Name
    ) AS t1
    INNER JOIN table2 t2  ON t1.Primary_pic = t2.post_id
                         AND t2.meta_key = 'Thumbnail';
    

    Updated SQL Fiddle Demo

    This will give you:

    |        NAME |               ADDRESS |          PHONE |  SEX | PRIMARY_PIC |                            PHOTO |      COMMENT |          THUMBNAIL |
    ----------------------------------------------------------------------------------------------------------------------------------------------------
    | John Sample | Sample Street,Country | 10000000000000 | Male |           2 | image3.jpg,image1.jpg,image2.jpg | Content Text | John_thumbnail.jpg |
    | Mark Sample |   Mark Street,Country | 20000000000000 | Male |           6 | image1.jpg,image2.jpg,image3.jpg |   Mark  Text | Mark_thumbnail.jpg |
    


    Update 3

    For this new meta_data column you will need one more join to the second table as we did for the primary pic like this:

    SELECT 
      t1.Name,
      t1.Address,
      t1.Phone,
      t1.Sex,
      t1.Photo,
      t1.Comment,
      t2.meta_value AS 'Thumbnail',
      t3.meta_value AS 'meta_data'
    FROM
    (
      SELECT
        p.Post_Name AS Name,
        MAX(CASE WHEN t.meta_key = 'Address' THEN t.meta_value END) AS 'Address',
        MAX(CASE WHEN t.meta_key = 'Phone' THEN t.meta_value END) AS 'Phone',
        MAX(CASE WHEN t.meta_key = 'Sex' THEN t.meta_value END) AS 'Sex',
        MAX(CASE WHEN t.meta_key = 'Primary pic' THEN t.meta_value END) AS 'Primary_pic',
        GROUP_CONCAT(DISTINCT c.Post_Content  SEPARATOR ',') AS Photo,
        GROUP_CONCAT(DISTINCT p.post_Content) comment
      FROM
      (
        SELECT *
        FROM Table1 
        WHERE parent_id = 0
      ) AS p
      INNER JOIN table1 AS c ON p.ID      = c.parent_ID
      INNER JOIN table2 AS t ON t.post_id = p.id
      GROUP BY p.post_Name
    ) AS t1
    INNER JOIN table2 t2  ON t1.Primary_pic = t2.post_id
                         AND t2.meta_key = 'Thumbnail'
    INNER JOIN table2 t3  ON t1.Primary_pic = t3.post_id
                         AND t3.meta_key = 'meta_data';
    

    Like this

    This will give you:

    |        NAME |               ADDRESS |          PHONE |  SEX |                            PHOTO |      COMMENT |          THUMBNAIL |      META_DATA |
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    | John Sample | Sample Street,Country | 10000000000000 | Male | image1.jpg,image2.jpg,image3.jpg | Content Text | John_thumbnail.jpg | data_data_data |
    | Mark Sample |   Mark Street,Country | 20000000000000 | Male | image2.jpg,image3.jpg,image1.jpg |   Mark  Text | Mark_thumbnail.jpg | data_data_data |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table 'Post' has field: id, name, content, post_id When i create new post,
Sorry for bad english and bad title! I have the table post id title
i want to display all posts in Post table with say id=5 ...... controller
I have two tables. Table 1. ======== id post -------- Table 2. ======== id
I have a table column called post_tags within a table called posts where assigned
I have a mysql table which columns are post_id and post_msg. Now I want
Like Button's table LIKE_ID (unique like ID for each post) LIKES (number of times
First time post. As an example, say I have a table with 12 entries;
I need to add indexes to my table (columns) and stumbled across this post:
Im trying to create an ajax (post) event that will populate a table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.