Link to home
Start Free TrialLog in
Avatar of dshi15
dshi15Flag for United States of America

asked on

sql select statement

Hi Expert,

I have table student, I need select all student have same first name and last name, how I can do it?


student

Id  FName  LName
1    Mary       Lee
2    John       Stull
3    Mary       Lee

Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

select * from student where fname = lname
ASKER CERTIFIED SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Select * from student where id in
    (select id from student where count(*) > 1 group by fname, lname)  


Or...

Select s1.* from student s1 where exists
  (select 1 from student s2 where s2.fname = s1.fname and s2.lname = f1.lname and s1.id <> s2.id)