In today’s article, we will be learning the NOT EXISTS clause in PostgreSQL. You can think of NOT EXITS as the use of equal and not equal symbols.
We will operate with ogrenci_all and ogrenci_vf tables, let’s see these tables and start our example.
ogrenci_all table with student names:
ogrenci_vf table where student visa and final grades are entered:
Let’s list both of our tables as above and now list the students whose vize and final grades have not been entered.
1 |
SELECT*FROM ogrenci_all WHERE NOT EXISTS (SELECT*FROM ogrenci_vf WHERE ogrenci_all.no = ogrenci_vf.no); |
It is different when you pay attention to the ROWS numbers in the lower left corner of the pictures of the tables above, you can notice this by manually looking at the values in the no column in the tables with low number of records, but if the number of records in your tables is thousands or millions, I recommend you to use not exists.
In the example below, the student whose vize and final grade has not been entered is listed.