Sunday , April 28 2024

PostgreSQL Intersect Command

In today’s article, we will be discussing the Intersect command, which allows us to see the common data present in both tables.

It will be understood better through examples.

First, let’s create our database.

After creating the database, let’s connect to the database as follows.

If you see the image below after connecting to the database, it means that you are connected correctly.

Let’s create a database named class and course within the school database.

We have created two tables and now let’s enter data into them:

Assuming you have done everything correctly up to this point, let’s move on to the intersect example.

The intersect command will return records that are the same in both tables.

We will be asked for records whose classes have been opened. To do this, we will use the following command.

As a result of the query, we see that there are 10-A and 11-B. This is because the 10-A and 11-B records are common to both tables.

As a result of this query, we see that 10-A and 11-B are opened, but the class is not opened even though there is a student waiting to enroll in the 12-B class.

Loading

About Faruk Erdem

Leave a Reply

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

Categories