In today’s article, I will explain the use of the PostgreSQL EXISTS condition, which allows us to perform operations with the subquery set to TRUE or FALSE.
We will operate with ogrenci_all and ogrenci_vf tables, let’s see these tables and start our example.
Student_all table with student names:
ogrenci_vf table where student vize and final grades are entered:
We have seen our two tables above, now let’s list the students whose vize and final grades have been entered.
1 | SELECT*FROM ogrenci_all WHERE EXISTS (SELECT*FROM ogrenci_vf WHERE ogrenci_all.no=ogrenci_vf.no) |
As can be seen above, there are 9 students whose midterm and final grades have been entered, and one student’s grade has not been entered.
At the beginning of my article, I talked about returning TRUE and FALSE values.
The query result after the EXISTS statement is TRUE, that is, TRUE as there are 9 records matching the sogrenci_all table and ogrenci_vf table numbers.