How do I SELECT
multiple rows of the same data (same table) as a single row?
Use case: I'm building a contacts management tool. Some people may have multiple email addresses and/or phone numbers. Instead of having to manually add yet another LEFT JOIN
and return something such as the following:
//print_r($row1);
//email1, email2, email3, email4, phone1, phone2, phone3, phone4
I would prefer to have MariaDB return something visually along the lines of the following:
//print_r($row1);
//email, phone
//print_r($row1['email']);
//1@example.com,2@example.com,3@example.com
//print_r($row1['phone']);
//123-4567,456-7890,109-345
This would allow me to avoid static JOIN
s. How can this be accomplished using MariaDB?
A great example is SQL Server's STUFF
function.