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 2000 Forums
 SQL Server Development (2000)
 Comparing DATA, not TABLES

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-30 : 09:09:48
Jim writes "I am looking for a way to search two columns in a table with data specified from two columns in a different table.

I have an SQL database with a table that contains arrest records. For reference, I'll call this table ARRESTS. There is a NAME column and a BIRTHDATE column amongst other columns but those are the only two columns that are relevant for this query. This table is updated monthly using the import wizard.

I have created a table of names and birthdates that I want to monitor so when a monthly import is done, I can see if any names on my list have been added into this arrest record table. I'll call this table EMPLOYEES.

I would like to run something that will compare the EMPLOYEES list to the ARRESTS table and if there is a match, some indication will be returned that lists the name.

Thanks,

Jim"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-30 : 09:18:40
Something like

Select name from ARRESTS A where exists
(select * from EMPLOYEES where name=A.name)

Madhivanan

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

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-03-30 : 14:57:48
Arrested Employees !?
Where do you work Jim?

A simple join should do the trick;

select A.NAME, A.BIRTHDATE
from ARRESTS A
join EMPLOYEES E
on A.NAME = E.NAME and A.BITHDATE = E.BIRTHDATE

rockmoose
Go to Top of Page
   

- Advertisement -