By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

compare data in two tables

P: 5
I have two tables
emp - ( has two field)
Name Sal
Joe 45
Jack 50
Kate 67

Dept
Name Dept Sal
Joe IS 46
Jack IS 50
Kate IS 89


I need to write a query which gives in output the records whose column " sal " does not match
the other condition is that i can ignore the ones who Sal has a difference of just 1
in this case Joe has a difference of 1 so i shoudl not print that out.

Help me out in this

Thanks
May 11 '07 #1
Share this Question
Share on Google+
2 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
I have two tables
emp - ( has two field)
Name Sal
Joe 45
Jack 50
Kate 67

Dept
Name Dept Sal
Joe IS 46
Jack IS 50
Kate IS 89


I need to write a query which gives in output the records whose column " sal " does not match
the other condition is that i can ignore the ones who Sal has a difference of just 1
in this case Joe has a difference of 1 so i shoudl not print that out.

Help me out in this

Thanks
This will only work if the Names are exactly the same.
Expand|Select|Wrap|Line Numbers
  1. SELECT emp.Name, emp.Sal, Dept.Name, Dept.[Dept], Dept.Sal
  2. FROM emp INNER JOIN Dept
  3. ON emp.Name = Dept.Name
  4. WHERE emp.Sal - Dept.Sal >1
  5. OR Dept.Sal - emp.Sal > 1
Mary
May 12 '07 #2

P: 3
Looking to do something similar to this but the tables are in Different DB's?? I have the query working in Test like yours but can't figure out how to make it work across DB's?

I need to validate that Table 1/DB1 Feeder Number Exist in Table 2/DB2. If the valus is NOT in Table2/DB2 update flag to N in Table1/DB1

I am doing this using PL/SQL developer as tool....

Table 1 has 12 colums
table 2 has 25 colums
May 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.