Home » SQL & PL/SQL » SQL & PL/SQL » Need SQL Logic For Comparing Data Between Two Tabless (Oracle)
Need SQL Logic For Comparing Data Between Two Tabless [message #682806] Fri, 20 November 2020 18:35 Go to next message
nrk1979
Messages: 1
Registered: November 2020
Junior Member
Hi!

Table1:
Acct Cust Owner Name
1111 A111 PRIM Dan Jason
1111 B111 SECO Donna Jason
1111 C111 SECO July Jason

Table2:
Acct Cust Owner Name
2222 A111 PRIM Donna Jason
2222 C111 SECO July Jason
2222 DD22 SECO Jimmy James

I have to compare both the (table1.Cust and table1.Name) fields against the (Table2.Cust and Table2.Name) fields.

Since one customer in Table 1 and Table 2 are different (Dan Jason and Jimmy James) and all others are similar, I need to report both account numbers 1111 and 2222 stating that the customers are different.

This is like vlookup in excel. However, I am not sure if this is possible in Oracle. Can someone guide me?
Re: Need SQL Logic For Comparing Data Between Two Tabless [message #682807 is a reply to message #682806] Fri, 20 November 2020 21:15 Go to previous messageGo to next message
BlackSwan
Messages: 26757
Registered: January 2009
Location: SoCal
Senior Member
Welcome to the forum.
Please read the OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Re: Need SQL Logic For Comparing Data Between Two Tabless [message #682808 is a reply to message #682806] Sat, 21 November 2020 00:00 Go to previous messageGo to next message
Michel Cadot
Messages: 67572
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Welcome to the forum.
Please read the OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Indent the code, use code tags and align the columns in result.

Also always post your Oracle version, with 4 decimals (query v$version), as often solution depends on it.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Have a look at MINUS operator and FULL OUTER JOIN condition.

[Updated on: Sat, 21 November 2020 00:03]

Report message to a moderator

Re: Need SQL Logic For Comparing Data Between Two Tabless [message #682813 is a reply to message #682806] Sat, 21 November 2020 07:30 Go to previous message
Solomon Yakobson
Messages: 3010
Registered: January 2010
Location: Connecticut, USA
Senior Member
nrk1979 wrote on Fri, 20 November 2020 19:35

Since one customer in Table 1 and Table 2 are different (Dan Jason and Jimmy James) and all others are similar, I need to report both account numbers 1111 and 2222 stating that the customers are different.
So by different you mean both accounts have same customer but with different names. And if one account has customer that doesn't exist in other account that's similar (strange). If so:

select  t1.Acct,
        t2.Acct
  from  table1 t1,
        table2 t2
  where t1.cust = t2.cust
    and t1.name != t2.name
/
SY.
Previous Topic: Query with LIKE too SLOW...
Next Topic: Day book format
Goto Forum:
  


Current Time: Fri Dec 04 15:47:30 CST 2020