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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:54:02+00:00 2026-05-22T16:54:02+00:00

I have two tables: table1: ID | user | info —————— 1 1 data1

  • 0

I have two tables:

table1:

ID | user | info
------------------
1    1      data1
2    1      data2
3    2      data3

table2:

table1_id | array_info
------------------------
1             a  
1             b
2             a
3             d
3             g
3             m

How can I efficiently return the rows associated with a user such that I get info and an array of that ID’s associated array_info?

For instance, a query like "select ID, info from table1 where user = 1" but would also return [a,b] from table2 so that the result would be something like [1, data1, [a, b]] with the first row and [2, data2, [a]] with the second row. Similarly, "…where user = 2" should return something like [3, data3, [d, g, m]]. I don’t think MySQL returns things quite like this, but perhaps PHP can smooth over the input of a left join? It seems wasteful to replicate all the data in info if MySQL returns a separate row for each array_info, but I’m not sure there’s another way.

  • 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-22T16:54:02+00:00Added an answer on May 22, 2026 at 4:54 pm

    You could use a GROUP_CONCAT with a JOIN and then when you iterate over the results, use explode() to convert the concatenated string to an array.

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

Sidebar

Related Questions

I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User
I have a simple database with two tables. Users and Configurations. A user has
i have two tables table1 fields fid,fname,fage a ,abc ,20 b ,bcv ,21 c
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged
THE INFO Currently I have two tables I am working with- a POST table
I have two tables like User and UserInfo UsersInfo UserId UserName Email Password LastLoginDate
If I have two tables in a DB User and Userinfo (split for normalisation

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.