SQL concatenate rows query

Posted by bobobobo on Stack Overflow See other posts from Stack Overflow or by bobobobo
Published on 2010-05-21T21:29:44Z Indexed on 2010/05/21 21:30 UTC
Read the original article Hit count: 185

Filed under:
|

Say we have a table

table posts
+---------+-----------+--------------------------------+
| postId  | title     | status    | bodyText           |
+---------+-----------+--------------------------------+
|   1     | Hello!    | deleted   | A deleted post!    |
|   2     | Hello 2!  | deleted   | Another one!       |

Can we, in SQL, retrieve a concatenation of a field across rows, by issuing a single query, not having to do the join up in a loop in our back-end code?

Something like

select title from posts group by status ;

Should give "Hello!, Hello 2!"

© Stack Overflow or respective owner

Related posts about sql

Related posts about query