Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3442658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:41:45+00:00 2026-05-18T08:41:45+00:00

I have a table employee that has employee’s benefit data. I have a field

  • 0

I have a table employee that has employee’s benefit data.
I have a field in the table called isenrolled if field is 1 that means employee has enrolled for benefit and if field is 0 that means not enrolled.
My problem is i have multiple recs of a employee, that means Scott has two entries with isenrolled =1 and isenrolled =0.
I want to select only one rec of SCOTT where his isenrolled =1 and reject the one where isenrolled =0, that way i will get only unique recs for employees who has enrolled and who has not enrolled. How do i select those employees? I tried the qry below and it doesn’t work

select * FROM  employee e 
WHERE e.empid not IN( SELECT empid FROM employee  e2
WHERE e2.isenrolled =1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:41:46+00:00Added an answer on May 18, 2026 at 8:41 am

    First I set up some test data using:

    create table t4
    as select * from scott.emp
    
    alter table t4 add (isenrolled number(10))
    
    update t4
    set isenrolled = 0
    
    insert into t4
    (select emp.*, 1
    from scott.emp)
    

    At this point the t4 table has now two records for each employee (one where isenrolled = 0 and one where isenrolled = 1)
    alt text

    so I change ALLEN’s data so he has “opted” out

    delete from t4
    where ename = 'ALLEN'
    and isenrolled = 1
    

    This query then shows the data for ALLEN (1 record) and SMITH (2 records)

    select *
    from t4
    where ename IN ('ALLEN', 'SMITH')
    order by ename
    

    alt text

    Then to show just one record per employee (restricted to ALLEN and SMITH in this case) you could use:

    select t.*
    from t4 t
    where isenrolled = (select MAX(isenrolled)
                        from t4
                        where t4.empno = t.empno)
    and ename IN ('ALLEN', 'SMITH')
    

    alt text

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
Say I have a table named EMPLOYEE, and the table has a field called
Suppose I have employee and department table, employee has foreign key departmentID that is
Ok, So I have a dim called Employee that has Employee_ID and the ID
Suppose I have a table called Companies that has a DepartmentID column. There's also
So I have a table that has, employee number, employee name, supervisor number. I
I have a table tblEmpl which has a column employeename . In that employee
Lets say I have a table called Employees , and each employee has a
I have a table that stores employee names and years they worked. The columns
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.