Monday , November 25 2024

PostgreSQL Select

In today’s article, we will cover What is Select and How to Write a Basic Select Statement.

Select is a postgresql sentence used to convey the data in the desired column on the Table to the user.

To explain through an example, you went to the grocery store and there are a lot of fruits and vegetables, but you only want to buy apples and cherries, so you choose apples and cherries from among the many products and tell the grocery store how many kg you will buy.

The same logic in PostgreSQL, you can select the data in the table according to the column you want and return it to you.

The usage is as follows:

Or:

When using the SELECT clause, you can select the columns you want to see the data for and write between SELECT and FROM.

If you are writing more than one column, you need to put a period between them.

But I want to see the data in all columns and do I have to write them all one by one?

No, it will be enough to write * between SELECT and FROM for this.

In the table below, we pull all the records in the Name and Surname columns in the Personnel table.

We can make various changes on the data with the Select operation.

In the example below, we have written a select clause to see the sum of the vize and final exam grades of the students in the student table.

If you only want to add two numbers, or just want to print text, you can do as in the examples below.

Example:

We did the following example using *, and since our table has 3 records and 3 columns, we have 3 columns and 3 records.

If we want to extract only the name and vize columns, we need to do as follows.

Loading

About Faruk Erdem

Leave a Reply

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