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

  • Home
  • SEARCH
  • 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 6555313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:48:14+00:00 2026-05-25T12:48:14+00:00

Here’s a morning challenge: you have a table with rows like this: => select

  • 0

Here’s a morning challenge: you have a table with rows like this:

=> select * from candidates;
 id |   name   
----+----------
  1 | JOhn Doe
  2 | Melinda
  3 | Bill
  4 | Jane
(4 rows)

=> select * from evaluation order by id;
 id | score |                reason                
----+-------+--------------------------------------
  1 | RED   | Clueless!
  1 | AMBER | Came in dirty jeans
  2 | GREEN | Competenet and experienced
  2 | AMBER | Was chewing a gum
  3 | AMBER | No experience in the industry sector
  3 | AMBER | Has knowledge gaps
(6 rows)

John has a red, Melinda has a green and amber, Bill has just ambers while Jane hasn’t been interviewed yet.

Your mission, should you choose to accept it is to generate a query that displays the results for Boss’ approval. Boss likes to have results presented as:

  • If a candidate has a GREEN, then display just greens and ignore reds and ambers.
  • If candidate has reds and ambers or just ambers then display all of them, but have red score appear first so he can skip ambers if RED is really bad.
  • display GREY for all candidates that have not been yet interviewed (‘Jane’)

Rules of the game:

  • No functions! Must be a single SQL query (however many sub-queries you want)
  • Any SQL variant accepted, but ANSI SQL 92 or later gets you more points
  • Try to avoid inline variables if you can (@foo in MySQL)

My own answer turned out to be in line with group-think:

SELECT *
FROM   evaluation e1
       NATURAL JOIN candidates
WHERE  score = 'GREEN'
        OR ( score IN ( 'RED', 'AMBER' )
             AND NOT EXISTS (SELECT 1
                             FROM   evaluation e2
                             WHERE  e1.id = e2.id
                                    AND score = 'GREEN') )
UNION
SELECT id,
       'GREY'              AS score,
       'Not yet evaluated' AS reason,
       name
FROM   candidates
WHERE  id NOT IN (SELECT id
                  FROM   evaluation)
ORDER  BY 1,
          2 DESC  
  • 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-25T12:48:15+00:00Added an answer on May 25, 2026 at 12:48 pm

    The following is transitional SQL-92:

    SELECT c.name, e.*
      FROM candidates AS c
           JOIN (
                 SELECT *
                   FROM evaluation
                  WHERE score = 'GREEN'
                 UNION
                 SELECT *
                   FROM evaluation AS e1
                  WHERE score IN ('AMBER', 'RED')
                        AND NOT EXISTS (
                                        SELECT * 
                                          FROM evaluation AS e2
                                         WHERE e2.id = e1.id
                                               AND e2.score = 'GREEN'
                                       )                                    
                ) AS e 
              ON c.id = e.id
    UNION
    SELECT c.name, c.id, 'GREY', '(not interviewed)'
      FROM candidates AS c
     WHERE NOT EXISTS (
                       SELECT *
                         FROM evaluation AS e 
                        WHERE e.id = c.id
                       )
    ORDER BY id, score DESC;
    

    Alternate (Intermediate SQL-92):

    SELECT c.name, e.id, e.score, e.reason 
      FROM candidates AS c
           JOIN (
                 SELECT *
                   FROM evaluation
                 EXCEPT
                 SELECT *
                   FROM evaluation
                  WHERE score IN ('AMBER', 'RED')
                        AND id IN ( SELECT id FROM evaluation WHERE score = 'GREEN' )
                ) AS e 
              ON c.id = e.id
    UNION
    SELECT name, id, 'GREY' AS score, '(not interviewed)' AS reason
      FROM candidates
     WHERE id NOT IN ( SELECT id FROM evaluation )
    ORDER BY id, score DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a coding problem for those that like this kind of thing. Let's see
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY
Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here is what I am trying to achieve in PHP: I have this string:
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here we go again, the old argument still arises... Would we better have a
Here's the basic setup: I have a thin bar at the top of a

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.