Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concat the output of the subquery?

Tags:

mysql

i have a query which would return values but i need them as a single output separated by commas..

So i tried to concat the output with the comma but it didn't work?

select id from videos where duration=0;  /// this would return some rows 

I tried concat and concat_ws but didn't work

select concat(select concat(id,',') from videos where duration=0); select concat((select id from videos where duration=0),','); select concat_ws(',',(select id from videos where duration=0)); 

i need the id's of all rows with the comma separtor

for example the output should be 1,4,6,78,565

any ideas?

like image 395
Vijay Avatar asked Sep 28 '10 12:09

Vijay


People also ask

Can we use ORDER BY clause in subquery?

ORDER BY command cannot be used in a Subquery. GROUPBY command can be used to perform same function as ORDER BY command. Use single-row operators with singlerow Subqueries. Use multiple-row operators with multiple-row Subqueries.

Can we use group by and ORDER BY in subquery?

An ORDER BY command cannot be used in a subquery, although the main query can use an ORDER BY. The GROUP BY command can be used to perform the same function as the ORDER BY in a subquery.

Does subqueries return a single value?

A subquery can return no value, a single value, or a set of values, as follows: If a subquery returns no value, the query does not return any rows. Such a subquery is equivalent to a null value.


1 Answers

This is what group_concat does.

select group_concat(id) as video_list from videos  where duration=0 
like image 169
Martin Smith Avatar answered Sep 21 '22 15:09

Martin Smith