I have this Type of Query,
select StateName ,countryName
from country_master left join state_master on country_master.countryID = state_master.countryID
which produce following result,
Gujarat India
Delhi India
HR India
MP India
NY USA
LA USA
Chicago USA
WDC USA
London Uk
I want this result in single row with its relation like,
India – Gujarat Delhi HR MP
USA
– NY LA Chicago Uk – London
Have Any Idea For Building this Query
Suggest Me,
Thanks,
This question is essentially a duplicate of Concatenate many rows into a single text string?.
Here is one method that works in Sql Server 2008:
You can see several methods for pulling off this kind of technique here: https://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/
You’ll need to be careful if your concatenated list of cities is going to be longer than 8000 characters, though you might be able to get away with doing something like varchar(max) if that’s a concern (aside from the fact that it probably wouldn’t be a very good way to look at the data).