Posts

Showing posts with the label Sub-Queries

SubQueries

Single Row_SubQuery -------------------- Single-Row Sub-Queries Returns one value SELECT <columns> FROM <table_name> WHERE <col_name> <OP> (SELECT STMNT); > , >=, <, <=, =. <> A single-row subquery in Oracle SQL is a subquery (a query nested inside another query) that returns only one row. The main/outer query uses the inner query result as its conditions If single row sub-query returns more than one row then you will get an error ORA-01422: exact fetch returns more than requested number of rows) It can be used in Select, Where, Having clauses Single Row_SubQuery -------------------- --1. Find who is getting highest salary in the employee table? select max(sal) from emp; select *from emp where sal=(select max(sal) from emp); select max(salary) from employees; select *from employees where salary=(select max(salary) from employees); --2.Find second maximum salary emp? select *from emp where sal=( select max(sal) from emp where sal!=(select max(sa...