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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:24:43+00:00 2026-06-08T12:24:43+00:00

How to join multiple row into one row without group concat ? Consider i

  • 0

How to join multiple row into one row without group concat ?

Consider i have table like below:

Table user:

uid | name
-----------
 1  | A
 2  | B

table meta:

uid | metaid | metaval
------------------------
 1  |   1    |  Jsep St.
 1  |   2    |  St. Oak No. 15
 2  |   1    |  Dt. San Joseph
 2  |   2    |  St. Oak No. 17
 2  |   3    |  OA.

table metaproperty:

metaid | metakey
-----------------
  1    | school
  2    | address 
  3    | dept
  4    | acc

I want to pick a user with their school and address so the query is

SELECT 
    uid, name, metaval 
FROM user 
INNER JOIN meta ON meta.uid = user.uid 
WHERE meta.metaid = 1 OR meta.metaid = 2

it will output

| UID | Name | MetaVal         |
--------------------------------
|  1  |  A   |  Jsep St.       |
|  1  |  A   |  St. Oak No. 15 |

The result I want is like this

uid | name | school  |    address 
-------------------------------------
 1  |   A  | Jsep St.| St. Oak No. 15

With group concat, metaproperty with value “school” and “address” is not in different column but one column

I try to join twice and it work but i think it’s not elegant

SELECT 
    uid, name, T1.metaval as school, T2.metaval as address 
FROM user 
INNER JOIN meta T1 ON T1.uid = user.uid AND T1.metaid = 1 
INNER JOIN meta T2 ON T2.uid = user.uid AND T2.metaid = 2

Any better solution ?

  • 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-08T12:24:46+00:00Added an answer on June 8, 2026 at 12:24 pm

    Any better solution ?

    Short answer

    No.

    Medium length answer

    There are a few problems with your query.

    • You forgot to include the user table.
    • Format your SQL to make it easy to read.
    • Consider using LEFT JOIN if some data might be missing.

    Try this:

    SELECT uid, name, T1.metaval AS school, T2.metaval AS address
    FROM user
    LEFT JOIN meta T1 ON T1.uid = user.uid AND T1.metaid = 1
    LEFT JOIN meta T2 ON T2.uid = user.uid AND T2.metaid = 2
    

    Long answer

    Yes, that query is ugly, but the problem is not the query but the database design. The design you are using is called entity-attribute-value (EAV). Avoid using the EAV design if at all possible! Whenever you use EAV, all your queries turn into multiple join monsters. It’s much easier if you can store each value in a separate column in the same row.

    Of course, there are some situations where you must use EAV. Then you just have to accept that your queries will be long, hard-to-read, inelegant and slow. That’s the tradeoff you make for having a flexible schema.

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

Sidebar

Related Questions

I have a mysql query that uses union to join multiple queries into one
I have to join queries from multiple databases, something like: SELECT T1.*, T2.* FROM
I have three tables, table one (tableA) containing users data like name and email,
Is there a way to join multiple row lines a single one using two
I have a dynamic search query with join multiple tables, for showing sum and
I've always been confused on how to combine multiple MySQL queries into one. I've
MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple
I've been trying to load multiple files into a table, so that they would
I know you can combine multiple table-selects using a Join statement but is there
MYSQL Database: I have a table of data that I need to put into

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.