MySQL - Compare 2 tables - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Skype & Technology (/forumdisplay.php?fid=9) +---- Forum: Tech Talk (/forumdisplay.php?fid=17) +----- Thread: MySQL - Compare 2 tables (/showthread.php?tid=92510) MySQL - Compare 2 tables by Jimbo on 10-08-2009 at 01:55 PM
What I am trying to do, is query 2 tables, and list all the differences between integer fields, if the difference is > 10. I have been thinking about ways to do this, and havent really come up with one. RE: MySQL by matty on 10-08-2009 at 01:58 PM Are the table definitions the same? As in each column is the same? Are you trying to do it based on rows? Like does TableA.Row1 = TableB.Row1? RE: MySQL by Jimbo on 10-08-2009 at 01:59 PM
The 2 table definitions are exactly the same, one is just an older backup I have. quote: What I am looking to compare are the playerupgrade1-4 fields from each record if the difference is > 10. RE: MySQL - Compare 2 tables by matty on 10-08-2009 at 02:18 PM
Really crappy way of doing it... not sure if it works but give it a shot. sql code: RE: MySQL - Compare 2 tables by Jimbo on 10-08-2009 at 02:19 PM
Just tried it: quote: Running MySQL 5.1, if that makes a difference. RE: MySQL - Compare 2 tables by matty on 10-08-2009 at 03:02 PM
Oops I screwed up sql code: RE: MySQL - Compare 2 tables by Jimbo on 10-08-2009 at 03:19 PM
That seems to work nicely, thanks a lot RE: RE: MySQL - Compare 2 tables by CookieRevised on 10-08-2009 at 07:21 PM
quote:Meaning you need to check if A is more than 10 bigger than B AND if A is more than 10 smaller than B, correct?. So... quote:That will not list values in B which are at least 10 bigger than A; it will only list values in B which are at least 10 less than A! Thus the correct clause would then be: sql code:ABS() = take the absolute value of the number ------------ EDIT: quote:Ah... In that case I never said anything RE: MySQL - Compare 2 tables by Jimbo on 10-08-2009 at 07:57 PM Well, the nature of my table, makes it impossible for the record to decrease from B to A, and all I wanted to do was list values in B that are at least 10 less than A. Maybe I should have worded what I required a bit easier, Matty's query seemed to work fine though. RE: MySQL - Compare 2 tables by matty on 10-08-2009 at 08:09 PM If you want to speed it up you should use indexs. |