Ruslan
Ruslan

Reputation: 319

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'

Upvotes: 3

Views: 1447

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181280

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.

Upvotes: 3

Related Questions