Introduction to SQL Statement-Query Statement (SELECT)

SQL-SELECT

Article Directory


This article talks about the SELECT statement about the establishment of the database table structure, I use postgreSQL to achieve it, the others should be similar, mainly to understand SQL statements

Select statement is a statement used to perform query operations. Simple to say is actually simple, but difficult to say. The select statement can be very simple to query all the data in a table like this.
Insert picture description here
Of course, you can also write very complex query statements, as shown below (I picked up a picture on the Internet and brought it over):
Insert picture description here
Therefore, select is the core of the query, and it is necessary for us to study it.

grammar

The grammar part is always so simple

SELECT column_name [, column_name]
FROM table1 [, table2]
WHERE [CONDITIONS]

The syntax of the SELECT statement is to select the column name first, then specify a certain TABLE from FROM, and finally you can choose to add some additional conditions.

After understanding the basic grammar, the focus is on how to use it. This is the secret of the SELECT statement.

Instance

Still based on our database operations, yes yes

  1. Query all student information
SELECT * FROM students;

Insert picture description here

  1. Query the student ID, name and date of birth of all male students
SELECT sno,sname,sbirthday FROM student WHERE ssex='M';

Insert picture description here

  1. Query the student ID, name, gender, date of birth of all female students born before "1980-01-01"
select sno,sname,ssex from student where (ssex='F' and sbirthday < '1980-1-1');

Insert picture description here

  1. Query the student ID, name, gender, and date of birth of all male students with the surname "Li"
select sno,sname,ssex,sbirthday from student where sname like 'L%';

Insert picture description here

Guess you like

Origin blog.csdn.net/RaynorFTD/article/details/109311736