SQL data search

zhaozj2021-02-17  53

Data retrieval

SELECT statements in SQL are often used to retrieve databases, or retrieve data that meets your settings, the following is a simple SELECT statement format:

Select "Column1" [, "Column2", ETC] from "TableName"

[Where "condition"];

[] = Optional

The names of the columns follow the Select keyword, which determines which column will be returned as the result. You can specify multiple columns arbitrarily, or you can use "*" to select all columns.

The name of the table is followed by the from keyword, it pointed out which form will be queried as the last result.

The WHERE clause (optional) indicates which data or row will be returned or displayed, which is based on the conditions described later in the keyword WHERE.

There can be the following conditional selection in the WHERE clause:

= Equal to

> Bigger than

> = Greater than or equal

<= Less than or equal

<> Does not equal

Like See the following comments

Note: The LIKE mode match operator can also be used in the conditional conditions of the WHERE clause. Like is a powerful operator that allows you to choose the "like" specified row. Percentage "%" can be used to match any possible characters, which can appear in front or behind, for example:

SELECT First, Last, City

From Empinfo

WHERE first like 'er%';

The above SQL statement will match any name starting with 'Er', where single quotes must be used.

Or you can use "%" in front of the character, for example:

SELECT FIRST, LAST

From Empinfo

WHERE LAST LIKE '% s';

This SQL statement will match any name ending with 's'. This "%" role is very similar to the "*" number of the DOS command.

SELECT * from Empinfo

WHERE first = 'ERIC';

The above SQL statement only selects the first name to 'Eric'.

转载请注明原文地址:https://www.9cbs.com/read-29985.html

New Post(0)