Combine records in one row with SQL -


how combine 2 records 1 row in sql query? data looks this:

name    | address     | address_type -------------------------------------- smith   | 123 main st | p  smith   | po box 123  | m 

i need result looks this:

name    | p_address   | m_address --------------------------------------- smith   | 123 main st | po box 123 

use conditional aggregate this

select name,        max(case when address_type = 'p' address end) p_address,        max(case when address_type = 'm' address end) m_address yourtable group name 

Comments

Popular posts from this blog

php - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

Reversible shuffling a int array in java -