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
 multi table lookups

Author  Topic 

cbillson
Starting Member

2 Posts

Posted - 2014-09-12 : 04:30:20
Hi, wonder if anyone could help me with this, and if its possible? I have some SQL experience, but nothing past basic commands. I'm trying to take some data held by an application to use as CSV import into another application.

I have two tables from an application, one holds references made in another.

The first tables holds details about a person:

field1=name field2=age field3=country

Joe,50,1

Country is held as a number, then there is another table that holds all the countries:

field1=id field2=description

1,USA
2,France
3,Germany

I want to do a lookup where it returns:

Joe,50,USA

in my head this is a select within a select, but i'm not even sure what to start searching in Google for this - can anyone assist?

Thanks
Chris

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-09-12 : 08:17:29
[CODE]
select NAME + ',' + CAST(age AS VARCHAR(10)) + ',' + descr
from @t1 t1
join @t2 t2
on t1.country = t2.id
[/CODE]
Go to Top of Page
   

- Advertisement -