-- Duplicate null columns can be detected.
Delete From [ Jcxs0201 ] Where User_id In ( Select User_id U From [ Jcxs0201 ] Group By User_id Having Count (ID) > 1 ) And ID Not In ( Select Min (ID) From [ Jcxs0201 ] Where User_id In ( Select User_id From [ Jcxs0201 ] Group By User_id Having Count (ID) > 1 ))
-- Duplicate null Columns cannot be detected.
Delete From [ Jcxs0201 ] Where User_id In ( Select User_id U From [ Jcxs0201 ] Group By User_id Having Count (ID) > 1 ) And ID Not In ( Select Min (ID) From [ Jcxs0201 ] Group By User_id Having Count (ID) > 1 )
PS: later repeated tests/2012 10 18
Found in (null ,~) Null is invalid, which is equivalent to in (~)
So here is a problem: If the column contains a null value in the group by column
It can only be described by a non-null value, such as the ID of the modified row or the row number obtained by the row_number () function.
Analysis of the preceding statement errors:
It is described in two parts: user_id and ID.
I. Check user_id first
1. The effects of Count (ID) and count (user_id) after group by user_id are different.
The following statement indicates that three rows of user_id are null, and count (null) seems invalid.
2. Make the userid in (null, 1257646) and user_id in (1257646) statements consistent, and the previous null will be ignored.
In fact, all results are user_id in (1257646 ).
Can it be understood that, in SQL Server, null is not a value, but a default status?
2. Check the group ID.
The statement containing grou by user_id does not know whether the select ID can be used.
If not, null cannot be processed. Therefore, the row_number () function must be used to add a row number to it.
This is my understanding. Please point out any errors