• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Compare two tables data

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello eveyone,
There are 2 tables both tables having the same columns(id, name,salary). The salary of Table 2 is changed for some id's. Now I want the data for those whose salary is different from Table 1.

I tried this but not success. Please someone help me.

 
Marshal
Posts: 25812
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't it be easier to just join the two tables and use a where-clause to only include the matched records which have different salary values? As a general rule you should always prefer having the database engine do that sort of logic rather than writing Java code to do it.
 
Paul Clapham
Marshal
Posts: 25812
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!

(By the way are the salary values really stored as String data in your database tables? Hopefully they aren't. And then you shouldn't treat them as String in your Java code either.)
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do this in the database with SQL, not in Java. Depending which database you're on, you may be able to use set operators to make it easier. Using SQL to run the query in the database means you don't have to move all the data across the network, you can use a proper query language, and the query engine can take advantage of any indexes to improve performance.
 
Paul Clapham
Marshal
Posts: 25812
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also by the way, don't use the == to check whether the contents of two String objects are the same. You should use the equals() method instead.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic