Merging the results of multiple tables
Hi there,
I'm a veteran computer programmer, but new to mySQL, so I'm a little lost on how to do a particular query.
I have two tables. The first table is "users", the second table is "songs". The idea is that each user (one record in the users table) can upload several songs (several records in the songs table).
I have it so that each new Song added, has a foreign key that points to a user record. So dozens of Songs could all point to the same user.
My question is, I want to run a query that returns information about a user, including all their songs. So, the return table would look like
username alias songname1 songname2 songname3
username alias songname1 songname2
username alias songname1 songname2 songname3 songname4
etc.. The songnames come from the SONGS table, and username/alias come from the USERS table, but the final result should be one table. What I've managed to get working is returning all the songs of a user, but as different rows in the table:
username alias songname
Bob bob Happy Song
Bob bob Sad Song
Bob bob Super Song
But I really want that to be returned as:
username alias songname1 songname2 songname3
Bob bob Happy Song Sad Song Super Song
So I want to merge n number of sub records, into a single user record, and return the results as 1 per user.
How do I perform this feat?
Thanks,
Glen
Subject
Written By
Posted
Merging the results of multiple tables
March 25, 2005 06:40PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.