SQL: Menggunakan Subquery

SELECT ename, hiredate
FROM emp
WHERE LOWER(ename) != 'blake'
AND deptno = (SELECT deptno FROM emp WHERE LOWER(ename) = 'blake');
SELECT empno, ename
FROM emp
WHERE sal > (SELECT AVG(sal) FROM emp) ORDER BY sal DESC;
SELECT empno, ename
FROM emp
WHERE deptno IN (SELECT deptno FROM emp WHERE ename LIKE '%T%');
SELECT ename, sal
FROM emp
WHERE empno IN (SELECT e.empno FROM emp e, emp m WHERE e.mgr=m.empno AND
LOWER(m.ename) LIKE 'king');
SELECT deptno, ename, job
FROM emp WHERE deptno = (SELECT deptno FROM dept WHERE LOWER(dname) = 'sales');
SELECT empno, ename
FROM emp
WHERE deptno IN (SELECT deptno FROM emp WHERE ename LIKE '%T%') AND sal >
(SELECT AVG(sal) FROM emp);
Advertisements
Posted in SQL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s