SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 Select Data based on Another Table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nadhym
Starting Member

Maldives
2 Posts

Posted - 04/10/2012 :  04:35:04  Show Profile  Reply with Quote
Hi..
I need a query to select data from two tables and set the value of a column based on the data on table 2.
example:
Table 1 contain student name and ID.
Table 2 contain ID and grade.

result should contain, the ID, name ( selected from table 1 based on the ID) and grade.

webfred
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 04/10/2012 :  11:03:28  Show Profile  Visit webfred's Homepage  Reply with Quote
select
t1.ID,
t1.name,
t2.grade
from table1 as t1
left join table2 as t2 on t2.id = t1.id


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

nadhym
Starting Member

Maldives
2 Posts

Posted - 04/11/2012 :  01:35:09  Show Profile  Reply with Quote
Thank You Webfred.. :)
Example was just a Sample
But i want the name to be selected based on the ID.
Which means if the ID is '70', the query should search it from Table 1.

Thank you Again..
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 04/11/2012 :  02:57:11  Show Profile  Visit webfred's Homepage  Reply with Quote
Do you know the WHERE clause?

Just add
WHERE t1.ID = 70
at the end of the query


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000