php - Retrieving and formatting all hasMany records in column of a MySQL result -


i'm not sure if possible straight mysql query (without manipulating data after), have been pondering on something...

say have 1 table, authors, , books. authors can have many books, , indicated author_id column in books table.

is there way perform query that:

1) retrieves single author record, column name 'books' holds array of book records, belonging author.

2) same result, authors in database.

any input on whether possible or not, , methods appreciated!

update

here's example of desired output of first query:

stdclass object ( [id] => 1 [name] => test author [age] => 28 [books] => array ( [0] => stdclass object ( [title] => book 1 [id] => 1 ) [1] => stdclass object ( [title] => book 2 [id] => 2 ) ) ) 

1) yes, group_concat() can (although don't best way d o it).

2) yes, group by author


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -