remove duplicates from a row and keep the order sql

I have a table as follows

SeriesVariables_ID     SeriesVariables_Label     SeriesVariables_Value    Series_ID
143                    Batch Number              Test20PassAll            28
144                    SerialNo                  SIMTEST                  28
145                    Seg Pull Date             20/1/2014                28
146                    Seg Pull Time             101010                   28
147                    Batch Number              Test20PassAll            28
148                    SerialNo                  SIMTEST                  28
149                    Seg Pull Date             20/1/2014                28
150                    Seg Pull Time             101010                   28
151                    Batch Number              Test20PassAll            7
152                    SerialNo                  SIMTEST2                 7
153                    Seg Pull Date             20/2/2014                7
154                    Seg Pull Time             202020                   7

What I would like is to keep the order of the table and remove the duplicates. The result will look something like this

SeriesVariables_ID     SeriesVariables_Label     SeriesVariables_Value    Series_ID
143                    Batch Number              Test20PassAll            28
144                    SerialNo                  SIMTEST                  28
145                    Seg Pull Date             20/1/2014                28
146                    Seg Pull Time             101010                   28
151                    Batch Number              Test20PassAll            7
152                    SerialNo                  SIMTEST2                 7
153                    Seg Pull Date             20/2/2014                7
154                    Seg Pull Time             202020                   7

Any help is greatly appreciated!

Answers


If you are running SQL, I've found the answer at https://stackoverflow.com/a/18949/1781207 to be very helpful for these situations. It will also keep the lowest SeriesVariables_ID as you want.

For example, in your code it should be (where "MyTable" is the name of your table)

DELETE MyTable 
FROM MyTable
LEFT OUTER JOIN (
   SELECT MIN(SeriesVariables_ID) as RowId, SeriesVariables_Label, SeriesVariables_Value, Series_ID
   FROM MyTable 
   GROUP BY SeriesVariables_Label, SeriesVariables_Value, Series_ID
) as KeepRows ON
   MyTable.SeriesVariables_ID = KeepRows.RowId
WHERE
   KeepRows.RowId IS NULL

You can test to see the selected rows by running the inner select statement alone

SELECT MIN(SeriesVariables_ID) as RowId, SeriesVariables_Label, SeriesVariables_Value, Series_ID
FROM MyTable
GROUP BY SeriesVariables_Label, SeriesVariables_Value, Series_ID

Need Your Help

Hiding password entry input in python

python passwords tkinter

I am trying to make a little log in program. But i am not sure if there is a way to replace the "password" with stars when you type the password. This is my code: