Niraj
Niraj

Reputation: 163

Separate single record into two rows by column names

I want to separate a single record into 2 records by their column names.

enter image description here

Consider only a single record for now.

Currently what I get using simple select query:

{ "id" : "1", "route_name" : "6", "start_up" : "Mumbai", "destination_up" : "Delhi", "start_down" : "Delhi", "destination_down" : "Mumbai" }

What I actually need:

{ "id" : "1", "route_name" : "6", "start_up" : "Mumbai", "destination_up" : "Delhi" }, { "id" : "1", "route_name" : "6", "start_down" : "Delhi", "destination_down" : "Mumbai" }

How can I achieve this using a single query?

Upvotes: 0

Views: 32

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

you can use an union

select id, route_name, start_up, destination_up 
from my_table 
where id ='1'
union 
select id, route_name, start_down, destination_down
from my_table 
where id ='1'  

Upvotes: 1

Related Questions