Last Updated on Monday, 19 November 2012
Unfortunately I make a living using Microsoft and Oracle products. I shouldn't say unfortunately as I don't see myself doing any other job and it beats daytime television any day.
I use this quite a lot so I thought I'd put an article here somewhere. Based on the following concept:
- RowID column_to_return_as_string
- --------- --------------------------
- 1 Me
- 2 Myself
- 3 I
- -- to be returned as
- RowID my_field_name
- --------- --------------------------
- 1 Me,Myself,I
Note that the following queries include the nested version because I find myself needing to group concatenate more often from another table then using data from the same table.
MySQL
- SELECT
- (
- SELECT
- GROUP_CONCAT(column_to_return_as_string)
- FROM
- a_pretend_table
- WHERE
- a_condition=true
- ) AS my_field_name
- FROM
- another_pretend_table
T-SQL
- SELECT
- STUFF(
- (
- SELECT
- ',' + column_to_return_as_string
- FROM
- a_pretend_table
- WHERE
- a_condition=true
- FOR XML PATH ('')
- ),1,1,''
- ) AS my_field_name
- FROM
- another_pretend_table
Oracle
- SELECT
- (
- SELECT
- wmsys.wm_concat(column_to_return_as_string)
- FROM
- a_pretend_table
- WHERE
- a_condition=true
- ) AS my_field_name
- FROM
- another_pretend_table
Latest Posts
-
Joes Revolver Map (JRM)
-
Fri 17-May-13
Hmmm... Sounds like a problem with the identifier. Was it working before and has there been a change ...
-
Fri 17-May-13
Hello Joel: Yes, I do have it published on all pages of the site. I just went back to Revolver maps to ...
-
Fri 17-May-13
Hi Bill, From the developers of RevolverMaps, "the module would need to be published on every page ...
-
Fri 17-May-13
Hi Bill, I'll investigate further as you're not the first to say this happens. In the meantime, simply ...
-
Fri 17-May-13
Its a great extension. But when I set it up I only show my presence on the 3D map and no other visitors ...
-
Fri 17-May-13


Comments
For the T-SQL, is there a way to do it with out the FOR XML PATH (''), I am trying to GROUP_CONCAT 2 cell [1111] and [2222] which all belong to ID column as
ID
1111
2222
My desired out put will be [1111,2222],rig ht now I am getting TAG_SEAL>111122 22, which have something to do with the FOR XML PATH (''). And if I get rid of it, it give me error "Subquery returned more than 1 value."
Your help is much appreciated !!!
RSS feed for comments to this post