M
M
ML2017-01-06 13:00:42
MySQL
ML, 2017-01-06 13:00:42

Is it possible to get the result with a Mysql collection?

Query example:
Mysql query:

SELECT
                t1.`ID`,
                t1.`title`,
                
                t2.`first_name`,
                t2.`last_name`
            FROM `posts` AS `t1`
            LEFT JOIN `users` AS `t2` ON t1.`ID` = t2.`post_id`;

result:
[0] => {
'ID' => 140,
'title' => 'title one',
'first_name' => 'name',
'last_name' => 'family'
}
...

And I would like something like:
[0] => {
      'ID' => 140,
      'title' => 'title one',
      'user_data' => {
            'first_name' => 'name',
            'last_name' => 'family'
      }
}
...

I can do this via php, but looping through, filtering and overwriting an array with large data (will be harsh).
Maybe it's possible to do something with the help of alias or something else in the request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-01-06
@Rsa97

No. MySQL only returns results as flat tables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question