A problem was encountered yesterday, querying all records in the user table that have the same user name. The problem at first glance is simple, but it's not that easy to think about. The first reaction of the mind is to read a piece of data after the loop looks for there is no same,
As follows: Select U1. * FROM M_user u1,m_user U2 where U1. Name = U2. Name and U1.rowid <> U2.rowid
found that when the user name of the same record more than two times there will be a problem, each record will be queried two times. For example,the name of the ID 1, 2, 3 Records is User1, then 1 and 3, 2 and 3, 1 and 2 will be queried,
That is, each record was detected two times. This is not possible, so back to the SQL statement. You can do this by using GROUP by. Copy Code Select * from m_user where namein (select Name ss from M_user where IsDeleted=0 GROUP by Name have count (*) > 1 )
Querying all records with the same name in the database