Tuesday , December 3 2024

PostgreSQL SUBQUERY

In today’s article, we will be cover about nested queries, namely SUBQUERY.

In order to write a SUBQUERY, we need to pay attention to some conditions.

Some of these are as follows.

SUBQUERYs are written after the first query.

SUBQUERY must be written in parentheses.

Appropriate operators should be used according to the number of records from SUBQUERY.

For example, let’s take the average of the vize grades in our ogrenci table and list the ones that are higher than the average.

First, let’s query the ogrenci table and see the data.

We have seen our data, now let’s view the people who took the Bilgisayar Mühendisliği course and whose vize is above the class average.

In the section below, the average of the midterm grades in the second select sentence from the left is 53.444 .

To see values higher than this number, it is sufficient to use the greater than sign.

To make the above example, we write the columns we want.

I took the vize column to see the adi, soyadi and vize grades, after that, after the WHERE clause, I took the average of the visze in the SELECT clause by opening parenthesis as I will take the average of this visa.

We have done the above operations with arithmetic operators, but apart from these, there are PLPGSQL clauses listed below.

ALL
ANY
OF
EXISTS
NOT EXISTS

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *