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
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Get data by matching two columns in two tables

Author  Topic 

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-02-25 : 09:25:28
Hello Friends,

I have a table A as follows:

ID Name
1 A
2 B
3 C
4 D


I have another table B as follows:
ID Message Date JobStatus
1 Good 01/01/2009 Completed
2 Good 02/03/2009 Pending
3 Poor 01/03/2009 Approved
4 Good 02/02/2009 Completed


From the above two tables, I want to create a new table as follows:
Name Message Date JobStatus
A Good 01/01/2009 Completed
B Good 02/03/2009 Pending
C Poor 01/03/2009 Approved
D Good 02/02/2009 Completed

Which means that I want to know if there is a way to write a SQL query that will help me to get the Names of the ID's by matching the ID's.

To be more clear, in the new table that I will be creating, I want to see that if in table A, ID is 1, then it should check table B, ID and retrieve the name from it as A.
So, in place of ID's 1, 2, 3 or 4, I want to see the names A, B, C or D.

I would be here to answer any questions if I am unclear in my question above.

Thanks,
notes4we

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-02-25 : 09:28:14
yes, look at INNER JOIN in Books Online, surely after over 50 posts, you should understand simple joins?!?
Go to Top of Page
   

- Advertisement -