My SQL table is something like this:
id, name, value1, value2, value3, value4
1, xyz, 1, 2, 4, 1
2, xyz, 4, 2, 4, 1
3, abc, 4, 2, 4, 1
4, abc, 4, 2, 2, 1
5, abc, 4, 2, 2, 1
I want to write a Sql query which returns rows which has any of their values (read: value1,value2,value3,value4) changed. So the result output would be:
id, name, value1, value2, value3, value4
1, xyz, 1, 2, 4, 1
2, xyz, 4, 2, 4, 1
4, abc, 4, 2, 2, 1
I understand, if I just needed values in output I could have used Distinct or Group by like:
select distinct value1,value2,value3,value4 from table;
But, here I need id and name columns too in output.
Wondering if I really need to write a subquery or create virtual/inner table to get my result. Or, there is a smarter way?
My question is not similar to How to find out whether a table has some unique columns. Let me know if you think otherwise, I can clarify.
Try this
SQL FIDDLE EXAMPLE