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 |
|
Leeoniya
Starting Member
8 Posts |
Posted - 2008-03-13 : 18:04:09
|
| I have 3 tables: Entity, EntityAddress, AddressSubTypeEntity has fields containing some account info.EntityAddresses has fields like Address1, City, Zip, etc.AddressSubType has fields like Home, Business, Office, etc.each entity can have multiple addresses, so if i do a JOIN on these tables, i will get several records for each entity, 1 per Address. This is not what i would like.I would like to make a select statement where the resulting table will contain columns like "HomeAddress1", "BusinessCity", "BusinessFax", etc. but only have 1 record per entity in the result.can someone show me a sample of how this can be done?thanks,Leon |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-03-13 : 21:33:22
|
| select * from entityleft outer join(select address1 as homeaddress from entityaddresses where addresstype='HOME') homeaddresson homeaddress.entityid=entity.entityidleft outer join(select city as businesscity, fax as businessfax from entityaddresses where addresstype='BUS') businessaddresson homeaddress.entityid=entity.entityidetc.At least I think that's what you mean. |
 |
|
|
Leeoniya
Starting Member
8 Posts |
Posted - 2008-03-14 : 14:34:53
|
| thats exactly it, thanks. |
 |
|
|
|
|
|
|
|