Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
siasfouche
Starting Member
5 Posts |
Posted - 2008-09-04 : 01:25:01
|
| Hi.For ex.I have table beers and table spirits looking likeBeersName Beer_drink UnitsPeter Guiness 3Peter Castle 2Mark Guiness 4Mark Windhoek 1SpiritsName Spirit_drink UnitsPeter Brandy 2Peter Gin 1Mark Wishkey 3Mark Cane 2I would now like to combine these tables to look like:All_DrinksName Alcoholic_drink UnitsPeter Guiness 3Peter Castle 2Peter Brandy 2Peter Gin 1Mark Guiness 4Mark Windhoek 1 Mark Wishkey 3Mark Cane 2 Can anybody help please.Thanks |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-09-04 : 01:31:06
|
| Try,select [Name],Beer_drink AS [Alcoholic_drink],Units from BeersUNIONselect [Name],Spirit_drink AS [Alcoholic_drink],Units from Spirits |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-04 : 01:34:44
|
| since one table contain beer info and other spirits, its reasonable to assume that you wont have duplicates when doing merging. so its better to use UNION ALL as its much better in performance than UNION.select [Name],Beer_drink AS [Alcoholic_drink],Units from BeersUNION ALLselect [Name],Spirit_drink AS [Alcoholic_drink],Units from Spirits |
 |
|
|
|
|
|