I have written this query on oracle database.
Select salary from emp having salary < (SELECT MAX(SALARY) FROM EMP ));
http://sqlfiddle.com/#!4/47961/13
But it is not working .
Where am i wrong?
I have written this query on oracle database.
Select salary from emp having salary < (SELECT MAX(SALARY) FROM EMP ));
http://sqlfiddle.com/#!4/47961/13
But it is not working .
Where am i wrong?
things to do,
WHERE
(use having when comparing with aggregated condition)eg.
Select salary
FROM emp
WHERE salary < (SELECT MAX(SALARY) FROM EMP );
Two errors:
WHERE
instead of HAVING
.Try this:
SELECT salary
FROM emp
WHERE salary < (SELECT MAX(salary) FROM emp);
Select salary from emp where salary < (SELECT MAX(SALARY) FROM EMP ));
you can apply having
clause where you used group by , here there is no group by than just use where
The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.
Correct way using Having in Oracle:
SELECT sal FROM scott.emp
GROUP BY sal
HAVING sal < (SELECT MAX(SAL) FROM scott.EMP)
/
SELECT deptno, COUNT(*) total_emps_by_dept
FROM scott.emp
GROUP BY deptno
HAVING COUNT(*) > 1
/
having
is used in combination withGROUP BY
to narrow down results