1

How can I create a similar query using Postgres to recreate this MySQL version.

SELECT u.id, GROUP_CONCAT(CONCAT(r.firstname,' ',r.lastname, ' [', r.type,']') SEPARATOR ', ') AS names FROM reference r, users u WHERE r.user_id = u.id GROUP BY r.user_id 

1 Answer 1

3

Use string_agg. Also, use explicit join syntax.

SELECT u.id, string_agg(r.firstname || ' ' || r.lastname || ' [' || r.type || ']' , ', ') AS names FROM reference r join users u on r.user_id = u.id GROUP BY r.user_id 
Sign up to request clarification or add additional context in comments.

1 Comment

This worked perfect, thanks! Been struggling with this for a bit so much appreciated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.