samedi 20 juin 2015

sql query to join and concat values

sql server: 2012

These are 3 tables.

First table is the user's (consultants) table The second one is the prices table, each user from the first column has a price The last table define in what area (city) the consultants offer services

Consultants      Prices           Area
uid | Name       uid | Price      uid | City
----|-----      -----|-------     ----|------
1   | Dave        1  |  5           1 | NY
2   | Adrian      2  |  7           1 | LA
3   | John        4  |  5           4 | NY
4   | Lee                           4 | NO
                                    4 | LA 
                                    4 | SF

I need to select from all the table something like this:

uid  |  Price   | City
-----|----------|-------
 1   |    5     | NY, LA
-----|----------|-------
 2   |    7     | 
-----|----------|-------
 4   |    5     | NY, NO, LA, SF
-----|----------|-------

How do I do this select? Any idea?

Aucun commentaire:

Enregistrer un commentaire