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 |
|
vinoth124
Starting Member
4 Posts |
Posted - 2008-07-14 : 07:32:56
|
| Hi Friend,I need your help to resolve this issue...,I need to fetch data from two tables with some condition...,For example, I am having two table named as TableA and TableB.TableA consist of 5 cols Name,Age,Area,Mark,Percentage.TableB consist of 5 cols lognumber,area,code,district,countryI need to fetch "Area" from TableA where Name='Vinoth'. With referto the output(Area) i need to fetch "code" from TableB.TableA:Name Age Area Mark Percentage Vinoth 23 che 88 88Ram 23 che 88 88Vinoth 23 mas 88 88Vinoth 23 kar 88 88Vinoth 23 tri 88 88TableB:lognumber area code district country1819 che 55 chennai india1820 mas 56 chennai india1816 kar 88 karur india Output Should be :Area Codeche 55mas 56kar 88tri nullCondition :1. O/p Area = Select area from tableA where name='Vinoth'2. 0/p Code = select code from tableB where area="o/p from prev step"Thanks in advance. Thanks,Vinoth R |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2008-07-14 : 07:39:52
|
A join perhaps?SELECT < list of columns wanted > FROM TableA LEFT OUTER JOIN TableB ON TableA.area = TableB.areaWHERE < desired where conditions > If you look in Books Online, you'll find a lot of info on joins and how they work. You can also look at the following article for a summary of the join types - [url]http://grounding.co.za/blogs/gail/archive/2008/04/03/joins.aspx[/url]--Gail ShawSQL Server MVP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-14 : 08:10:34
|
| [code] SELECT Area,Code FROM TableBWHERE Area IN (SELECT Area FROM TableA WHERE Name='Vinoth')[/code] |
 |
|
|
|
|
|
|
|