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
 A simple SQL Query question

Author  Topic 

eprices
Starting Member

4 Posts

Posted - 2007-05-25 : 19:02:26
I'm new to SQL Server 2005 and have a question that I know is very basic but that has confounded me for a while:



An example of a SQL query that would accomplish this would be greatly appreciated.

Thanks :)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-25 : 19:09:00
You would use an inner join.

SELECT t1.a, t2.b
FROM Table1 t1
INNER JOIN table2 t2
ON t1.a = t2.a
ORDER BY t2.b

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

eprices
Starting Member

4 Posts

Posted - 2007-05-25 : 19:12:45
thank you
thank you
thank you
Go to Top of Page

eprices
Starting Member

4 Posts

Posted - 2007-05-25 : 19:31:27
To take this one step further, if I have four tables...



Again, thank you so much for your help
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-25 : 19:40:23
Then you would add more joins to your query.

Doesn't your class material or your SQL book have examples of this?

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-25 : 19:41:09
basically you just INNER JOIN to the additional tables.

select t2.Name, t3.City, t4.State
from t1 inner join t2 on t1.NameID = t2.NameID
inner join t3 on t1.CityID = t3.CityID
inner join t4 on t1.StateID = t4.StateID



KH

Go to Top of Page

eprices
Starting Member

4 Posts

Posted - 2007-05-25 : 19:49:03
quote:
Originally posted by khtan


Thank you very much
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-26 : 01:50:24
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -