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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:42:01+00:00 2026-05-14T23:42:01+00:00

I have two tables that relates 1:n content ——— – id – title –

  • 0

I have two tables that relates 1:n

content
---------
- id
- title
- text

content_meta
-------------
- id
- content_id
- meta_key
- meta_value

A content can have multiple content_meta registers associated to it. Typically content_meta will contain the category, tags, descriptions and all that stuff, so I really don’t know the number of registers a content will have.

What I want to accomplish is to take the content register and also all the related registers in content_meta in a single query.
I’ve tried the subselect approachment but seems that I can only get one register/column (¿?)
SELECT content.*, (
SELECT *
FROM content_meta
WHERE content_id = content.id
)
FROM content

This query complains that “Operand should contain 1 column(s)”, so changing the ‘*’ by for example meta_key clears the error, but returns a NULL for this subselect…

SELECT content.*, (
                  SELECT meta_key
                  FROM content_meta
                  WHERE content_id = content.id
                 )
 FROM content

Can anybody show me where to go from here please?

  • 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-05-14T23:42:02+00:00Added an answer on May 14, 2026 at 11:42 pm

    Use:

    SELECT c.*,
           cm.*
      FROM CONTENT c
      JOIN CONTENT_META cm ON cm.content_id = c.id
    

    That will only return CONTENT and related when there is a supporting record in the CONTENT_META table. If it’s possible for a CONTENT record to not have any CONTENT_META data, use a LEFT JOIN instead:

       SELECT c.*,
              cm.* --these columns will be null if there is no supporting data
         FROM CONTENT c
    LEFT JOIN CONTENT_META cm ON cm.content_id = c.id
    

    Followup Question –


    it is now possible to group by content.id, but renaming the meta_key column with its own value and the value of this column the content of meta_value?

    MySQL doesn’t have PIVOT syntax – you have to use CASE statements:

      SELECT c.id,
             MAX(CASE WHEN cm.meta_key = 'A' THEN cm.meta_value ELSE NULL END) AS 'A',
             MAX(CASE WHEN cm.meta_key = 'B' THEN cm.meta_value ELSE NULL END) AS 'B',
             MAX(CASE WHEN cm.meta_key = 'C' THEN cm.meta_value ELSE NULL END) AS 'C'
        FROM CONTENT c
        JOIN CONTENT_META cm ON cm.content_id = c.id
    GROUP BY c.id
    

    You’ll have to specify the meta_key for each one you want to appear in the resultset.

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

Sidebar

Related Questions

I have two tables that have virtually identical content and very similar structure. They
I have two tables that are related via a mapping table: keywords titles I
I have two tables that link together through an id one is submit_moderate and
I have two tables that I want to join together. Table1 Year, ID, Theme,
I have two tables that should be joined together by a foreign key relationship,
I have two tables that are considered a single entity in my domain model.
I have two tables that I am joining with the following query... select *
Suppose I have two tables that are linked (one has a foreign key to
Let's say I have two tables that look like this: TH TH TH TH
If i have two tables that have nothing in common I want to do

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.