Query to get column value comma separated [duplicate] - sql

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
Is there an Oracle SQL query that aggregates multiple rows into one row?
Agregate rows in Oracle SQL statement
I am working with Oracle 10g. I want to have a comma separated String from a column in a table.
e.g.
Table : Customer
Columns: id and name
Data:
id-------name
1-------John
2-------Galt
3-------Howard
4-------Roark
Output of query should be Jon,Galt,Howard,Roark

Ok, got it, all I wanted was this:
SELECT WM_CONCAT(NAME) FROM CUSTOMER;
Marking all comments as +1. Thanks guys.

Related

SQL Select AS not being recognized as column [duplicate]

This question already has answers here:
Referring to a Column Alias in a WHERE Clause
(9 answers)
Closed 1 year ago.
I am using a simple select statement and creating a column using a CONCAT function and labeling the column as Filter.
Why is the new column not being recognized?
Error message states
Invalid Column Name - Filter
You can't refer to column aliases in the where clause as the where is processed before the alias is materialised.
There are several workarounds, and assuming SQL Server you can do
select *
from table t
cross apply (values(concat(columna,columnb)))c([filter])
where [filter]='something'
Also note that the performance won't be great on large data sets since this criteria is non-sargable

How to use WHERE clause on a field with comma seperated values in MS SQL SERVER? [duplicate]

This question already has answers here:
Filter rows by matching comma separated list against comma separated list
(3 answers)
Split String Value in SQL for Flexible Filtering
(4 answers)
Closed 1 year ago.
I have a table with a field with values stored in the "STANDARD,ELITE,DELUXE" format. I want to find all the rows where this field contains a defined value, e.g. ELITE or ELITE,DELUXE.
How can I perform a query in MSSQL SERVER to search a value in a field like this one?
Any help would be highly appreciated.
Thank you,

List aggregation in Oracle 10G [duplicate]

This question already has answers here:
Concatenate results from a SQL query in Oracle
(7 answers)
Closed 6 years ago.
Lets say, I have following table(i.e: Reference Table). I want to display my results as 'Expected Table'. How may I get this result? Any help will be highly appreciated. I am using Oracle 10g.
Expected:
SELECT Collateral_Id,
LISTAGG(Commitment_Id, ',')
WITHIN GROUP (ORDER BY Commitment_Id) "Commitment_Id"
FROM yourTable
GROUP BY Collateral_Id

What is the sql query to display the data types of each column in an oracle database table? [duplicate]

This question already has answers here:
How to view all the Metadata of columns of a table in oracle database?
(2 answers)
Closed 8 years ago.
What is the sql query to display the data types of each column in an oracle database table?
For example lets say I have a table called workflow_status with the following columns.
WORKFLOW_STATUS_ID, STATUS_NAME, LABEL, CREATED_DATE, UPDATED_DATE
What is the SQL query that will display the datatype of WORKFLOW_STATUS_ID, STATUS_NAME, LABEL, CREATED_DATE and UPDATED_DATE?
In Oracle, the DESC command is used to describe a table.
DESC workflow_status;

comma separated value in sql [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Concat all column values in sql
I have a table
ID | Name
1 | X
2 | y
3 | z
I have to show values in column Name as comma separated i.e x,y,z.
One way I can do is looping the values of column "Name" and displaying as comma separated.
Is there is a other way to do it.Please help.
Even though this is a duplicate of several other questions, I'd like to give an answer, because the easiest way to do this has changed recently. Oracle has provided the very nifty LISTAGG function with the following syntax:
SELECT
LISTAGG(name, ',') WITHIN GROUP (ORDER BY name)
FROM
my_table;
LISTAGG is available since Oracle 11.2.