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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select twice columns on single row

Author  Topic 

avr
Starting Member

1 Post

Posted - 2009-12-27 : 07:40:44
I have the following

Table1
areaid, area_latitude, area_longitude

Table2
areaid_a, areaid_b, area_a_name, area_b_name

what I want my sql query to return is to bring in one row the latitude and longitude for both the areas for which areaid_a=areaid and areaid_b=areaid

ie
area_latitude, area_longitude, areaid_a, areaid_b, area_latitude, area_longitude, area_a_name, area_b_name

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-12-27 : 11:59:02
You can join table2 twice with different aliases:

select ...
from table1 t1
join table2 t2a
on t2a.ariaid_a = t1.areaid
join table2 t2b
on t2b.ariaid_b = t1.areaid


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -