dshi15
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
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
select * from student where fname = lname
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Select * from student where id in
(select id from student where count(*) > 1 group by fname, lname)
(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)
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)