简体   繁体   中英

How to find a specific name without "WHERE" in an Oracle schema?

Here is my screenshot for my homework, which uses the Oracle sample Human Resources schema:

HERE IN THE SCREENSHOT

So, my result list is the same as on the link above. But the query used is not acceptable in my homework. Since the assignment says:

"you cannot use either 'WHERE E.DEPARTMENT_ID=D.DEPARTMENT_ID' or any 'JOIN' statement in the query string."

I am using Oracle Database 10g Express Edition.

Do you have any idea what my teacher wanted me to consider?

Here is my code:

SELECT   D.DEPARTMENT_NAME AS depName, LAST_NAME || ', ' || FIRST_NAME AS empName 
  FROM   DEPARTMENTS D, EMPLOYEES E 
  WHERE  E.DEPARTMENT_ID=D.DEPARTMENT_ID 
UNION ALL 
SELECT   '!w/o department!' AS reszleg, FIRST_NAME || ' ' || LAST_NAME AS empName 
  FROM   EMPLOYEES E 
  WHERE  DEPARTMENT_ID IS NULL 
ORDER BY depName, empName

Do you have any idea what my teacher wanted me to consider?

I guess that the teacher want to know if you have learned the HAVING clause.

The HAVING clause is usually associated with GROUP BY clause, but it also can be used without GROUP BY , and in this case it works in the same way as ordinary WHERE clause.

Please examine this demo: http://sqlfiddle.com/#!9/dcb16/60277

SELECT *
FROM ForgeRock
WHERE id = 2;

SELECT *
FROM ForgeRock
HAVING id = 2;

Both queries give the same result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM