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 7612007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:48:20+00:00 2026-05-31T01:48:20+00:00

I come across this pattern occasionally and I haven’t found a terribly satisfactory way

  • 0

I come across this pattern occasionally and I haven’t found a terribly satisfactory way to solve it.

Say I have a employee table and an review table. Each employee can have more than one review. I want to find all the employees who have at least one “good” review but no “bad” reviews.

I haven’t figured out how to make subselects work without knowing the employee ID before hand and I haven’t figured out the right combination of joins to make this happen.

Is there a way to do this WITHOUT stored procedures, functions or bringing the data server side? I’ve gotten it to work with those but I’m sure there’s another way.

  • 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-31T01:48:22+00:00Added an answer on May 31, 2026 at 1:48 am

    Since you haven’t posted your DB Structure, I made some assumptions and simplifications (regarding the rating column, which probably is number and not a character field). Adjust accordingly.

    Solution 1: Using Joins

    select distinct e.EmployeeId, e.Name
    from employee e
    left join reviews r1 on e.EmployeeId = r1.EmployeeId and r1.rating = 'good'
    left join reviews r2 on e.EmployeeId = r2.EmployeeId and r1.rating = 'bad'
    where r1.ReviewId is not null --meaning there's at least one
    and r2.ReviewId is null --meaning there's no bad review
    

    Solution 2: Grouping By and Filtering with Conditional Count

    select e.EmployeeId, max(e.Name) Name
    from employee e
    left join reviews r on e.EmployeeId = r.EmployeeId
    group by e.EmployeeId
    having count(case r.rating when 'good' then 1 else null end) > 0
    and  count(case r.rating when 'bad' then 1 else null end) = 0
    

    Both solutions are SQL ANSI compatible, which means both work with any RDBMS flavor that fully support SQL ANSI standards (which is true for most RDBMS).

    As pointed out by @onedaywhen, the code will not work in MS Access (have not tested, I’m trusting in his expertise on the subject).

    But I have one saying on this (which might make some people upset): I hardly consider MS Access a RDBMS. I have worked with it in the past. Once you move on (Oracle, SQL Server, Firebird, PostGreSQL, MySQL, you name it), you do not ever want to come back. Seriously.

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

Sidebar

Related Questions

Recently I have come across Command Pattern . In this pattern Client is responsible
Lately I have come across Null Object design pattern and my colleagues say it
Has anyone come across this issue? Seems MS have broken it with their own
I've recently come across this website. Now, is there any way I can actually
I've come across this issue in my application, and have reproduced it using Apple's
I have just come across this code: function test(){ //... if ( $profilerule ==
I come across this a lot, and have always been curious if there is
Recently I have come across a curious pattern in some code. We know that
Has anyone come across something like this before? Basically, I have an action on
I've been reading up on the Factory pattern, and have come across articles that

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.