Select multiple rows into a single row one after the other in Postgres

Pradnya

I am using postgresql and have a table 'sometable' which looks like this

id | ref_id |  a_remarks   | a_date     |  b_remarks   |  b_date
1  | 32     |  'send xyz'  | 20/06/2014 |  'file send' |  22/06/2014 
2  | 32     |  'send abc'  | 25/06/2014 |  'file send' |  01/07/2014 

but while displaying it to user i need to display it this way

20/06/2014  Send xyz
22/06/2014  file send
25/06/2014  send abc
01/07/2014   file send

so i am unable to view data one after the other since it is in different columns. Can any one help me with this?? Thanks In Advance.

Brett DiDonato

Create one query that selects a_remarks and a_date, union it with another query that selects b_remarks and b_date and then order by id. If it's important to strip out the id then create the unions in a subquery and just drop the id in the outer query. Like this...

SELECT t.date, t.remarks FROM (SELECT id, a_date AS date, a_remarks AS remarks FROM sometable UNION SELECT id, b_date AS date, b_remarks AS remarks ORDER BY id) t;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Postgres Multiple Rows as Single Row

From Dev

Postgres, split one row into multiple rows with conditions

From Dev

select single row from multiple rows by id

From Dev

Combining multiple rows into one single row

From Dev

how to select one row from one table and multiple rows from other table using joins in mysql,

From Dev

How to display one row when table has multiple rows related to Single record in other table?

From Dev

JOIN multiple rows to multiple columns in single row Netezza/Postgres

From Dev

Select from multiple rows as one row with defaults

From Dev

Select Multiple rows into one row in Oracle

From Dev

Postgres select from one to many table to single table rows

From Dev

Sum rows after comparing one row with multiple rows

From Dev

Select one row from multiple rows based on one field

From Dev

How to select multiple rows of mysql table as a single row

From Dev

Convert the multiple rows Select statement result into a single row string result

From Dev

How to select a single row where multiple rows exist from a table

From Dev

Insert multiple rows from a single row inside an insert into select query

From Dev

How to select a single row where multiple rows exist from a table

From Dev

How to convert multiple rows(but one column) into a single row in MySQL

From Dev

MySQL query - single row in one table with multiple rows in another table

From Dev

How to Stack mysql query results to select one row after the other

From Dev

sql query select only one row from multiple rows

From Dev

PostgreSQL select query 'join multiple rows to one row'

From Dev

MySql select values from multiple rows into one row

From Dev

Select one row from multiple rows based on availability

From Dev

Remove multiple lines & Display single line after one row

From Dev

Expand a single row into multiple rows

From Dev

Expand single row to multiple rows

From Dev

Single row to multiple columns and rows

From Dev

Paste into multiple rows and not a single row

Related Related

  1. 1

    Postgres Multiple Rows as Single Row

  2. 2

    Postgres, split one row into multiple rows with conditions

  3. 3

    select single row from multiple rows by id

  4. 4

    Combining multiple rows into one single row

  5. 5

    how to select one row from one table and multiple rows from other table using joins in mysql,

  6. 6

    How to display one row when table has multiple rows related to Single record in other table?

  7. 7

    JOIN multiple rows to multiple columns in single row Netezza/Postgres

  8. 8

    Select from multiple rows as one row with defaults

  9. 9

    Select Multiple rows into one row in Oracle

  10. 10

    Postgres select from one to many table to single table rows

  11. 11

    Sum rows after comparing one row with multiple rows

  12. 12

    Select one row from multiple rows based on one field

  13. 13

    How to select multiple rows of mysql table as a single row

  14. 14

    Convert the multiple rows Select statement result into a single row string result

  15. 15

    How to select a single row where multiple rows exist from a table

  16. 16

    Insert multiple rows from a single row inside an insert into select query

  17. 17

    How to select a single row where multiple rows exist from a table

  18. 18

    How to convert multiple rows(but one column) into a single row in MySQL

  19. 19

    MySQL query - single row in one table with multiple rows in another table

  20. 20

    How to Stack mysql query results to select one row after the other

  21. 21

    sql query select only one row from multiple rows

  22. 22

    PostgreSQL select query 'join multiple rows to one row'

  23. 23

    MySql select values from multiple rows into one row

  24. 24

    Select one row from multiple rows based on availability

  25. 25

    Remove multiple lines & Display single line after one row

  26. 26

    Expand a single row into multiple rows

  27. 27

    Expand single row to multiple rows

  28. 28

    Single row to multiple columns and rows

  29. 29

    Paste into multiple rows and not a single row

HotTag

Archive