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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:44:54+00:00 2026-06-10T13:44:54+00:00

Given a table of exam results, where 1 == PASS and 0 == FAIL

  • 0

Given a table of exam results, where 1 == PASS and 0 == FAIL


ID    Name    Test   Result
--------------------
1     John    MATH   1
2     John    ENGL   1
3     Mary    MATH   1
4     Mary    PSYC   0

EDIT: assume that the name is unique.

I need to get all records for people who

1) passed all tests
2) failed at least one test

So, the 1st query should return John and all his records, and the 2nd query should return Mary and all her records (including the ones with PASS).

I’m trying to do a LEFT OUTER JOIN with itself and compare counts, but don’t seem to get a working query.


SELECT * FROM Results R1
LEFT OUTER JOIN Results R2 on R1.ID=R2.ID and R2.Result=1
WHERE ??? count of rows from R1 is compared to count of non-null rows from R2
  • 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-06-10T13:44:55+00:00Added an answer on June 10, 2026 at 1:44 pm

    This is a “poster-child” exercise for the EXISTS clause:

    At leasr one failed result:

    select * from Results r
    where exists (select * from Results rr where rr.Name=r.Name AND Result=0)
    

    All passed:

    select * from Results r
    where not exists (select * from Results rr where rr.Name=r.Name AND Result=0)
    

    See how these queries work on your data set at sqlfiddle.com.

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

Sidebar

Related Questions

Given table USER (name, city, age), what's the best way to get the user
How to write a PL/SQL procedure that: Copies a table given by name into
I currently have a list of the top X results for a given table,
Given Table A Id INTEGER Name VARCHAR(50) Table B Id INTEGER FkId INTEGER ;
Given: Table y id int clustered index name nvarchar(25) Table anothertable id int clustered
Given table: ID ONE TWO X1 15 15 X2 10 - X3 - 20
Given the table: CREATE TABLE IF NOT EXISTS `users` ( `id` bigint(20) NOT NULL
Given: CREATE TABLE foo (id BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)); I'd like to
Given a table like: CREATE TABLE MyTable ( MyColumn NUMBER NOT NULL ); I
Given a table in MySQL with rows that have a 'Country' field, I need

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.