0

I have a following query description. How to express it in SQL?

Query -> list all the employee first name such that their emp_pct is less than any of the employee whose proj_num is 18 (Make use of ANY).

I have following table name EMP_2;

Name                           Type
-----------------------------------
EMP_NUM                        CHAR(3)
EMP_LNAME                      CHAR(15)
EMP_FNAME                      CHAR(15)
EMP_INITIAL                    CHAR(1)
EMP_HIREDATE                   DATE
JOB_CODE                       CHAR(3)
EMP_PCT                        NUMBER(5,2)
PROJ_NUM                       CHAR(3)
0

1 Answer 1

3

Here you go. The ANY keyword compares and short circuits the moment it finds a matching row in the sub-query.

SELECT a.EMP_FNAME 
FROM EMP_2 a
WHERE a.EMP_PCT < ANY (
  select EMP_PCT 
  from EMP_2 
  where EMP_NUM <> a.EMP_NUM and PROJ_NUM = 18);
Sign up to request clarification or add additional context in comments.

1 Comment

See this Question for more discussion of ANY. And see MySQL doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.