Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing two columns in different tables

Status
Not open for further replies.

corbinap

Programmer
Nov 20, 2006
34
US
How do I compare to columns in two different tables. By using Not in or Not Like. Can someone give me an example with two tables....Thanks.
 
NOt sure what you want could you be more specific? What have you tried?
usually I use a join and then (inthe where clause)something like
table1..field1 = table2.field1
or
table1..field1 > table2.field1
or
table1..field1 < table2.field1
or
table1..field1 <> table2.field1

depending on how I want to compare them.

"NOTHING is more important in a database than integrity." ESquared
 
I have seen some information on not having exist

I just need to compare two columns

PrevMonth from EmpHist table and Currentmonth from Emp table and see what fields in Currentmonth from Emp table do not match or is null compared to PrevMonth column in EmpHist table...
 
something like
Code:
select t1.* from table1 t1
join table2 t2 on t1.someidfield = t2.someidfield
where coalesce(t1.someotherfield, '')<>coalesce(t2.someotherfield, '')

If table1 might have records which do not have an equivalent record at all in table2 then use a left join

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top