Could someone tell me how to make an SQL query that selects all rows where at least 1 of 4 columns is different from the previous rows. I want the same you do with a GROUP only then affecting multiple columns. When I use:
SELECT * FROM TABLE GROUP BY col1, col2, col3, col4
I don't get the result I want because the columns are grouped after each other
col1 col2 col3 col4
1 2 2 4
1 2 2 3 <-- different -> select
1 2 3 2 <-- different -> select
1 2 3 2 <-- don't select
2 2 3 4 <-- different -> select
I don't want the 1 2 3 2 column 2 times and decide which one top pick based on a 5th column
-- Edit --
Sample data SQLfiddle: http://sqlfiddle.com/#!2/efd92e In this sample I want these rows returned
insert into tablename VALUES ("T", 12, 1000, 0, 500, 20.25); (4)*
insert into tablename VALUES ("H", 12, 150, 2500, 100, 45); (0)*
insert into tablename VALUES ("H", 12, 100, 2500, 100, 45); (2)*
*if it is possible, I also would like to know the number rows that not selected because they are "duplicated".
I Tried to write an query based on one of the awnser but no success yet
-- Clarification --
- The combination of the 5 cols has to be unique.
- I need the row of the duplicates with the lowest col6.
- I want to know how many duplicates of this row are in the database
Thanks in advance for the help