SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to compare differences between MySQL tables

    If I have two identical mysql tables (same name, same fields etc) how can I compare if the data is the same from each row?

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't quite get how you can have two tables with the same name...

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SJH View Post
    I don't quite get how you can have two tables with the same name...
    Ok, well not same name, but same structure etc..

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mind me asking why you're going to have two tables with the same structure? Sorry, not trying to be difficult, but this usually indicates a problem with database design that when rectified may well sort out the problem you're trying to solve here.

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am creating an auto upgrade feature for an application I have and would just like to see which tables I have updated since the last release.

  6. #6
    SitePoint Enthusiast freezea's Avatar
    Join Date
    Apr 2009
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To find different values in corresponding fields:

    SELECT a.PrimaryKey
    FROM TableA a
    INNER JOIN TableB b ON a.PrimaryKey = b.PrimaryKey
    WHERE a.FieldA <> b.FieldA
    OR a.FieldB <> b.FieldB
    etc...

    To find records in TableA that have no match in TableB:

    SELECT a.PrimaryKey
    FROM TableA a
    LEFT JOIN TableB b ON a.PrimaryKey = b.PrimaryKey
    WHERE b.PrimaryKey IS NULL
    RAQ Report: Web-based Excel-like Java reporting tool.

  7. #7
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Just a quick question; what does this part of the query do?

    PHP Code:
    WHERE a.FieldA <> b.FieldA
    OR a.FieldB <> b.FieldB 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •