Reputation: 31
I have table like this
ID travelname bemail mname temail tman_name
1 a xxx aa bbb cccc
2 b ddd bb xxxx ssss
I have a requirement like this
travelname email name
a xxx aa
a bbb cccc
b ddd bb
b xxxx ssss
I tried union query.
Any one plz help to me.
Thanks.
Upvotes: 1
Views: 1050
Reputation: 48207
With UNION
, you have to make sure both queries have same number of columns.
Second query doesn't really need to include names because it will use the first query names, but you include it for clear reading.
SELECT travelname,
bemail as email,
mname as name
FROM mytable
UNION
SELECT travelname,
temail as email,
tman_name as name
FROM mytable
Upvotes: 3