Penggunaan SUBQUERIES Di (ORACLE)

Teori Dasar

Subquery adalah Query didalam query. Artinya seleksi data berdasarkan hasil seleksi data yang telah ada. Sintax SQL nya sama syntax SQL pada umumnya, tetapi kondisi setelah where diikuti dengan query baru atau subquery. Syntaxnya :

SELECT  nama_field-1,…..,nama_field-n
FROM   nama_tabel
WHERE  kriteria (SELECT nama_field-1, ……., nama_field-n
                             FROM  nama_tabel
                             WHERE kriteria)

Contoh pemakaian QUERY

SELECT Last_name, salary, department_id, manager_id
FROM employees
WHERE salary =
                (SELECT salary
                 FROM employees
                 WHERE department_id=40) ; 

SELECT Last_name, salary, department_id, Manager_id
FROM employees
WHERE salary =
                (SELECT salary
                 FROM employees
                 WHERE department_id=40) 
AND   manager_id =
                (SELECT manager_id 
                 FROM employees
                 WHERE department_id=40) ; 


SELECT Last_name, salary, department_id, Manager_id
FROM employees
WHERE salary =
                (SELECT salary
                 FROM employees
                 WHERE department_id=40) 
OR   manager_id =
                (SELECT manager_id
                 FROM employees
                 WHERE department_id=40) ;


SELECT last_name, Department_id, salary
FROM employees
WHERE salary = ( SELECT MIN(salary)
                               FROM employees) ;

Postingan terkait:

Belum ada tanggapan untuk "Penggunaan SUBQUERIES Di (ORACLE)"

Post a Comment