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
 Query including 2 different tables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-23 : 08:59:48
Collin writes "i have tried to do a query between 2 different tables that have different columns. within both these tables there is a column that has a column name different from the column name of the other table but the data within both columns is the same. i wanted a query that compares the data between the 2 tables.

Example is:

Table 1
Columns : firstname , age , id , grade.

Table 2
Columns : name, sex , school.

lets say that the data of column "firstname" of table 1 contains the same data as column "name" of table 2 and i would want to do a query that retrieves records for where data in the column "firstname" in table 1 is found in column "name" of table 2.

sql server 2000 with service pack 3 running on windows 2003 server service pack 1
Rgds,
Mr. C. "

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-23 : 09:02:20
Read about Joins in sql server help file

Also 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

cmdr_skywalker
Posting Yak Master

159 Posts

Posted - 2006-05-23 : 13:13:25
in general, you might want to standardize the data domain (fullname vs last/first/middle names) to make sure that your matching algorithm follows the same assumptions.

in SQL, you can use JOINS, CHAINDEX, PATINDEX, IN, LIKE, SOUNDEX, etc. to find out if a column is the same (or partially the same) with the other column.

May the Almighty God bless us all!
Go to Top of Page
   

- Advertisement -