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

  • Home
  • SEARCH
  • 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 1050553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:47:14+00:00 2026-05-16T16:47:14+00:00

I have two tables, keywords and data. Table keywords have 2 columns (id, keyword),

  • 0

I have two tables, keywords and data.

Table keywords have 2 columns (id, keyword), table data have 3 columns (id[foreign key of keywords.id], name, value).

I am using this query:

SELECT k.id, d.value, d.name
FROM keywords AS k
INNER JOIN data as d ON k.id = d.id

it returns something like:

1 123 name1
1 456 name2
2 943 name1
3 542 name1
3 532 name2
3 682 name3

Each id can have values from 0 to 3 (maybe more in the future).

How can I retrieve all the rows with the same id in the same row?

Like

1 123 456
2 943
3 542 532 682

I want to do this because I want to be able to sort the values.

  • 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-16T16:47:15+00:00Added an answer on May 16, 2026 at 4:47 pm

    Use GROUP_CONCAT() like this:

     SELECT k.id, GROUP_CONCAT(d.value)
      FROM keywords AS k
      INNER JOIN data as d ON k.id = d.id
      GROUP BY k.id
    

    Also, you may need to do ORDER BY d.name to get exact order of values as you want. Like this:

     SELECT k.id, GROUP_CONCAT(d.value ORDER BY d.name separator ' ')
      FROM keywords AS k
      INNER JOIN data as d ON k.id = d.id
      GROUP BY k.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called keywords. It's simple, two columns - id and keyword.
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables. Lets say they look like this Table Sports: Column 1:
Let's say I have two tables: Table 1 has the columns NOTE_ID (a unique
I have two tables one is keywords [id | keyword | account] k and
I have two tables with a foreign key constraint how can I delete rows
I have two tables, Book and Tag , and books are tagged using the
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`

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.