How to create single row from multiple row?

Posted on

Question :

I have written a SQL with CASE statement in SELECT, which is creating different columns. And my query output is comping in multiple rows (Please refer attached picture of output).

enter image description here

But I want my output in single row like this:
enter image description here

Please let me know how can I achieve this is SQL. I am using PostgreSQL.

Thanks

Answer :

SELECT {columns without nulls}, MAX({columns with nulls})
FROM table
GROUP BY {columns without nulls}

Of course you must use separate expression for each separate column.

Leave a Reply

Your email address will not be published. Required fields are marked *