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 8504585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:04:36+00:00 2026-06-11T02:04:36+00:00

I have a MySQL DB with 2 tables. First table: Posts ID post_title post_content

  • 0

I have a MySQL DB with 2 tables.
First table:

Posts                                    
ID                      
post_title                      
post_content 
... etc

And second table with additional data:

Postmeta
ID
Post_ID (FK)
meta_key
meta_value

The data that I need is in the meta_key/value pairs. But this DB organized in the way that each row in the second table only have one piece of information.

For example (second table):

ID      Post_ID   meta_key        meta_value
1          5      info                 30

ID      Post_ID   meta_key        meta_value
2          5      additional_info      40

ID      Post_ID   meta_key        meta_value
3          6      info                 50

ID      Post_ID   meta_key        meta_value
4          6      additional_info      60

So if I run query

SELECT 
posts.id, 
posts.post_date, 
posts.post_author, 
posts.post_content, 
posts.post_title, 
postmeta.meta_id, 
postmeta.meta_key, 
postmeta.meta_value

FROM posts INNER JOIN postmeta ON posts.id = postmeta.post_id

WHERE posts.post_type = 'post'

I get back all data that I need but data from first table (ID/post_content etc) repeated many times.
But I only need data from first table once but all additional data from second table related to ID from the first table.

How I should filter all this stuff? May be some php loop?

  • 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-11T02:04:38+00:00Added an answer on June 11, 2026 at 2:04 am

    You can use a mysql group_concat function like this:

    select
        posts.id, 
        posts.post_date, 
        posts.post_author, 
        posts.post_content, 
        posts.post_title, 
        group_concat(postmeta.meta_id) as metaID, 
        group_concat(postmeta.meta_key) as metaKey, 
        group_concat(postmeta.meta_value_ as metaValue
    from
        posts 
            INNER JOIN postmeta 
                ON posts.id = postmeta.post_id
    where
        posts.post_type = 'post'
    group by
        posts.id, 
        posts.post_date, 
        posts.post_author, 
        posts.post_content, 
        posts.post_title
    

    The to split out the results in PHP you can easily use an explode function to form an array of the resulting information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have 3 Tables is my SQL Database: First Table: Room: ID <pk>, Roomname
I have a table in MySQL of contact information ; first name , last
I have two MySQL tables, j and t, with a third normalising table, jt.
This is my first ever question on SO. So I have a MYSQL table
I have a table called posts with the following struture: post_id | post_body |
I have MySQL tables looking like this: regions table id | region ------------------- 1
I have two MySQL tables something like this: tool_owners: tool_owners_id | user_id | ...
I have two MySQL tables structed as follows; advert +-------------------+--------------+ | Field | Type
I have two MySQL tables: attributes (attributeid, name) productsattributes (productid, attributeid, displayvalue) The required
I have 3 MySQL tables: shelf --------------- id project_id label books --------------- id project_id

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.