Find all rows where the value in one column only occurs once

  • Find all rows where the value in one column only occurs once

    Employee Sections

    harshan 12

    harshan 25

    mileen 2

    ajay 19

    Would it be possible to do a select on this table and only display rows where Employee occurs only once,:result will be like this

    Employee Sections

    mileen 2

    ajay 19

    harshan 12 (select first one)

    Any hints?

  • VG-619426 (4/7/2010)


    Find all rows where the value in one column only occurs once

    Employee Sections

    harshan 12

    harshan 25

    mileen 2

    ajay 19

    Would it be possible to do a select on this table and only display rows where Employee occurs only once,:result will be like this

    Employee Sections

    mileen 2

    ajay 19

    harshan 12 (select first one)

    Any hints?

    Like this:

    SELECT Employee, MIN(Sections) as Sections

    FROM EmployeeSections

    GROUP BY Employee

    HAVING COUNT(*) = 1

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • It's a little bit more work if you really only want the first Section.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply