Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 381749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:06:56+00:00 2026-05-12T15:06:56+00:00

I have a table (client) with 20+ columns that is mostly historical data. Something

  • 0

I have a table (client) with 20+ columns that is mostly historical data.

Something like:
id|clientID|field1|field2|etc…|updateDate

If my data looks like this:

    
    10|12|A|A|...|2009-03-01
    11|12|A|B|...|2009-04-01
    19|12|C|B|...|2009-05-01
    21|14|X|Y|...|2009-06-11
    27|14|X|Z|...|2009-07-01

Is there an easy way to compare each row and highlight the differences in the fields?
I need to be able to simply highlight the fields that changed between revisions (except for the key and the date of course)

There may be multiple fields updated in each new row (or just one).

This would be on a client by client basis so I could select on the clientID to filter.

It could be on the server or client side, which ever is easiest.

More details
I should expand my description a little:
I’m looking to just see if there was a difference between the fields (one is different in any way). Some of the data is numeric, some is text others are dates. A more complete example might be:

    
    10|12|A|A|F|G|H|I|J|...|2009-03-01
    11|12|A|B|F|G|H|I|J|...|2009-04-01
    19|12|C|B|F|G|Z|I|J|...|2009-05-01 ***
    21|14|X|Y|L|M|N|O|P|...|2009-06-11
    27|14|X|Z|L|M|N|O|P|...|2009-07-01

I’d want to be able to isplay each row for clientID 12 and highlight B from row 11 and C & Z from row 19.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:06:56+00:00Added an answer on May 12, 2026 at 3:06 pm

    Any expression in SQL must reference columns only in one row (barring subqueries).

    A JOIN can be used to make two different rows into one row of the result set.

    So you can compare values on different rows by doing a self-join. Here’s an example that shows joining each row to every other row associated with the same client (excluding a join of a row to itself):

    SELECT c1.*, c2.*
    FROM client c1
    JOIN client c2 ON (c1.clientID = c2.clientID AND c1.id <> c2.id)
    

    Now you can write expressions that compare columns. For example, to restrict the above query to those where field1 differs:

    SELECT c1.*, c2.*
    FROM client c1
    JOIN client c2 ON (c1.clientID = c2.clientID AND c1.id <> c2.id)
    WHERE c1.field1 <> c2.field1;
    

    You don’t specify what kinds of comparisons you need to make, so I’ll leave that to you. The key point is that in general, you can use a self-join to compare rows in a given table.


    Re your comments and clarification: Okay, so your “difference” is not simply by value but by ordinal position of the row. Remember that relational databases don’t have a concept of row number, they only have order of rows with respect to some order you must specify in an ORDER BY clause. Don’t confuse the “id” pseudokey with row number, the numbers are assigned as monotonically increasing only by coincidence of their implementation.

    In MySQL, you could take advantage of user-defined variables to achieve the effect you’re looking for. Order the query by clientId and then by id, and track values per column in MySQL user variables. When the value in a current row differs from the value in the variable, do whatever highlighting you were going to do. I’ll show an example for one field:

    SET @clientid = -1, @field1 = '';
    SELECT id, clientId, field1, @clientid, @field1,
      IF(@clientid <> clientid, 
        ((@clientid := clientid) AND (@field1 := field1)) = NULL,
        IF (@field1 <> field1, 
          (@field1 := field1), 
          NULL
        )
      ) AS field1_changed
    FROM client c
    ORDER BY clientId, id;
    

    Note this solution is not really different from just selecting all rows with plain SQL, and tracking the values with application variables as you fetch rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 219k
  • Answers 219k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The __TEXT, __const section is for non-relocatable initialized constant data.… May 12, 2026 at 11:47 pm
  • Editorial Team
    Editorial Team added an answer Why not sort the array by date (oldest first), then… May 12, 2026 at 11:47 pm
  • Editorial Team
    Editorial Team added an answer You should see Jetty instance(s) running in one of the… May 12, 2026 at 11:47 pm

Related Questions

I have many tables that use Lookup/Enum references for most of their column values.
I am wanting to have a view table that aggregates rows from four tables.
I'm trying to query a MySQL database using an array but I'm having trouble!
I have 3 kinds of objects: Agency, BusinessUnit and Client (each with their own

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.