Sub Query di Dalam Query Microsoft Access

Subquery adalah query di dalam query yang biasanya digunakan sebagai kriteria, yakni dalam sintak WHERE dan HAVING (namun subquery bisa juga diset di column). Subquery dapat diisikan didalam suatu query dengan statement:

• SELECT

• SELECT… INTO

• INSERT… INTO

• DELETE

• UPDATE

Hanya terdapat 3 (tiga) variasi akan penggunaan Subquery ini, yakni:

Variasi Subquery 1

Sintaknya: Comparison [ANY | SOME | ALL] (SQLStatement)

Contoh 1:

SELECT Title, Price

FROM BOOKS

WHERE Price > (SELECT Max(Price) FROM BOOKS2);

Contoh 2:

SELECT Title, Price

FROM BOOKS

WHERE Price > ALL

(SELECT Price

FROM PUBLISHERS INNER JOIN BOOKS ON PUBLISHERS.PubID =

BOOKS.PubID

WHERE PubName = “Big House”);

Variasi Subquery 2

Sintaknya: Expression [NOT] IN (SQLStatement)

Contoh:

SELECT Title

FROM BOOKS

WHERE Title NOT IN (SELECT Title FROM BOOKS2);

Variasi Subquery 3

Sintaknya: [NOT] EXISTS (SQLStatement)

Contoh:

SELECT PubName

FROM PUBLISHERS

WHERE NOT EXISTS

(SELECT * FROM BOOKS WHERE BOOKS.PubID =

PUBLISHERS.PubID);

Beri Nilai Artikel Ini:

Leave a Reply

Do NOT follow this link or you will be banned from the site!
%d bloggers like this: