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 |
|
sivaarc
Starting Member
9 Posts |
Posted - 2009-03-09 : 11:58:07
|
| i have a tables customer and customer address .Each customer have a one are many address. But i have to list only one address for one customer.. How can i achive this using sql query?---------------------Customer Year-------------------------aa 2005bb 2009cc 2008--------------------------Customer Address City------------------------aa 1 aaaa 2 bbbb 1 aabb 2 cccc 1 bblist should be like aa 2005 1 aabb 2009 1 aacc 2008 1 bb |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-03-09 : 12:04:10
|
| Can you show what you tried atleast? |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-03-09 : 12:04:33
|
| something like this..select a.customer,a.year,b.address,b.cityfrom customertable a inner join addresstable b on a.customer = b.customer and b.address = 1 |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-10 : 00:10:38
|
| try like this if ur using 2005 and above select customer,[year],address,city from (select row_number()over(partition by b.customer order by a.customer)as rid,a.customer,a.year,b.address,b.cityfrom customertable a inner join addresstable b on a.customer = b.customer )t where rid = 1 |
 |
|
|
sivaarc
Starting Member
9 Posts |
Posted - 2009-03-10 : 01:36:46
|
thank you......quote: Originally posted by bklr try like this if ur using 2005 and above select customer,[year],address,city from (select row_number()over(partition by b.customer order by a.customer)as rid,a.customer,a.year,b.address,b.cityfrom customertable a inner join addresstable b on a.customer = b.customer )t where rid = 1
|
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-10 : 01:47:30
|
quote: Originally posted by sivaarc thank you......quote: Originally posted by bklr try like this if ur using 2005 and above select customer,[year],address,city from (select row_number()over(partition by b.customer order by a.customer)as rid,a.customer,a.year,b.address,b.cityfrom customertable a inner join addresstable b on a.customer = b.customer )t where rid = 1
welcome |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|