Thursday, 22 August 2013

How To Check If Two Or More Rows Have The Same Field Value ?


you want to filter details from db.


The Problem :


I want to select the first row with the last name "usama" and then I want to skip the next row which has the same field "usama".


Database Example:


id| First Name| Last Name
1 | Saad | Usama
2 | Saad | Usama
3 | Saad | def

I found that it could be handled by the below:

Select Statement:

Select min(m.id) MY_Idenfire , m.First_Name, m.Last_NameFrom new_table m
Where identifier in (select distinct identifier from table_name)Group by  m.First_Name, m.Last_Name


Result:

1 | Saad | Usama
3 | Saad | def


Best OF Luck

No comments:

Post a Comment