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

Try this:
SQL Fiddle Demo
This will give you:
Then using PHP, you can display them the way you want.
Update
If you want to display the value of
user commentas comment, you can do this:Updated SQL fiddle Demo
Update2:
Based on the updated sample data:
SQL Fiddle Demo
This will give you:
Update 2
For the updated data, try this:
Updated SQL Fiddle Demo
This will give you:
Update 3
For this new
meta_datacolumn you will need one more join to the second table as we did for theprimary piclike this:Like this
This will give you: