sql select statement

Posted on 2011-04-30
Last Modified: 2012-05-11
Hi Expert,

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


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

Question by:dshi15
    LVL 40

    Expert Comment

    select * from student where fname = lname
    LVL 40

    Accepted Solution

    Or, find students with the same name?

    select * from student a join student b on a.fname = b.fname and a.lname = b.lname and <>
    LVL 42

    Expert Comment

    Select * from student where id in
        (select id from student where count(*) > 1 group by fname, lname)  

    LVL 42

    Expert Comment


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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
    Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now