tarsier Posted September 16, 2009 Share Posted September 16, 2009 Hello All, I have a SQL question and hope someone can point me in the right direction. I would like to do a query and have several columns reduce into a single result column. I will try to give a simple example here. I have a table that looks something like this account_name account_phone1 account_phone2 name1 555-555-1111 555-555-2222 name2 555-555-3333 555-555-4444 I would like to do a search like: SELECT {SQL MAGIC} WHERE account_name = 'name1' and get the result account_name phone name1 555-555-1111 name1 555-555-2222 Where phone1 and phone2 are combined into a single column. Is this possible? It will greatly reduce the complexity of my program. Thanks for any input you have. - Dave Link to comment https://forums.phpfreaks.com/topic/174519-is-it-possible-to-get-several-columns-to-stack-in-single-result-column/ Share on other sites More sharing options...
artacus Posted September 17, 2009 Share Posted September 17, 2009 There are several ways to do this, but probably the easiest would be a union SELECT account_name, account_phone1 AS phone FROM account WHERE account_name = 'name1' UNION ALL SELECT account_name, account_phone2 FROM account WHERE account_name = 'name1' Link to comment https://forums.phpfreaks.com/topic/174519-is-it-possible-to-get-several-columns-to-stack-in-single-result-column/#findComment-919872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.