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 - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -