Ruslan Ruslan - 3 months ago 21
SQL Question

Select result in single cell

How can I select all id's for records in single cell?

For example:

--example select of all values
select id, name, address, phone from table

And get all id's where phone like '%555%' and show them in single field like:
'111 123 234 321 231 234'


If you are using Oracle 11gR2:

select LISTAGG(id, ' ') WITHIN GROUP (ORDER BY id) from table

If you are not running Oracle 11gR2, check if wm_concat function is available and do:

select wm_concat(id) from table

Keep in mind that you might want to combine these functions with group by clauses. Check out link I gave you for more options.