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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:06:51+00:00 2026-05-22T17:06:51+00:00

I’m performing a simple query that joins two tables together. What I get is

  • 0

I’m performing a simple query that joins two tables together. What I get is something like this.

array(
    [0] => array(
        'id' => 52
        'name' => 'charles',
        'sale_id' => 921,
        'sale_time' => 1306393996,
        'sale_price' => 54.21
    ),
    [1] => array(
        'id' => 52
        'name' => 'charles',
        'sale_id' => 922,
        'sale_time' => 1306395000,
        'sale_price' => 32.41
    ),
    ...
);

…which is the expected result. However, I’d like the query to return something like this:

array(
    [0] => array(
        'id' => 52,
        'name' => 'charles',
        'sales' => array(
            [0] => array(
                'sale_id' => 921,
                'sale_time' => 1306393996,
                'sale_price' => 54.21
            ),
            [1] => array(
                'sale_id' => 922,
                'sale_time' => 1306395000,
                'sale_price' => 32.41
            ),
            ...
        )
    )
)

Now I realize I could simply perform two queries, one for the user info, and another for sales, and merge those arrays together using whatever language I’m using (PHP in this case). But I have many arrays of properties and querying and merging for those seems awfully inelegant to me (although it does work). It seems to me there’d be a way to work with a single, unified object without duplicating data.

Just wondering if there was a no-brainer query, or if that’s simply not easy through MySQL alone.

  • 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-22T17:06:52+00:00Added an answer on May 22, 2026 at 5:06 pm

    I would say this is not possible with MySQL alone – you have to do some tricks at application level. That is, because even if you send a single query that will bring you all the data from MySQL to your application (PHP), they will come as a denormalized array of data – your first case.

    If you want to get the data as in your second case, I’d recommend using some ORM – in Ruby there is ActiveRecord, in Perl there are Class::DBi, DBIx::Class and many more – I can not name one for PHP that is able to do this, but I am sure there are plenty.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have two tables with like below codes: Table: Accounts id | username |
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.