From the course: SQL: Data Reporting and Analysis
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Merge rows with GROUP BY - SQL Tutorial
From the course: SQL: Data Reporting and Analysis
Merge rows with GROUP BY
- [Instructor] So far, we've looked at numeric grouping functioned, but there is one string function that you can run on grouped data, and that's called group_concat. Postgre has string agg. Microsoft offers this function too now, as of SQL server 2017, and Oracle has list agg. So let's take a look at what this one does. Select district, group concat, phone. So, perhaps you want to call all of your customers, one city at a time. This query would help you to return all of your phone numbers, grouped by city. So there we have, where the district is blank, we have one number, you see that it's separated with a comma there, another number and so on. And there may be more than three numbers, it may not be showing us everything there. And some of them just have one value, and so on and so forth. And that could be useful if, for instance, you need to prepend dialing codes, or something like that, to the numbers that…