Database Learning (6) -- basic query operations database Learning (5) -- create and update a data table 2 http://www.bkjia.com/database/201305/207493.html In database operations, a developer or user needs to retrieve information in a data table to obtain data records. In SQL statements, the SELECT statement is used to retrieve data records. The SELECT statement can retrieve data in a data table or view and display the queried data as a result set. This chapter gives a comprehensive introduction to SELECT query statements. This chapter mainly introduces the basic operations of SELECT statement query. Query records of all columns in an SQL statement. To retrieve records of all columns in a data table, you must query all columns in the data table. In SQL statements, a method is provided to query all columns of a data table or view. The syntax format is as follows: SELECT * FROM table name or view name [, table name or view] Where the "*" sign after the SELECT statement queries all columns in the data table, the table name or view name after the FROM clause is used to specify the name of the data table or view to be queried. [] The specified table name or view is optional. That is to say, the FROM clause can be followed by multiple table or view names. Separate multiple tables or views with commas. Note: The names of a maximum of 256 tables or views can be specified after the FROM clause. Query the columns specified in a table in the actual development and application. In many cases, developers or users do not want to see all the records in the data table, if you are only interested in the data of one or more columns in the data table, you need to query the information of the specified columns in the data table. The syntax format for querying a specified column in a data table or view in a SELECT statement is as follows: SELECT target column [, target column,…] FROM table name or view name [, table name or view]. The target column after the SELECT statement indicates the name of the specified column to be queried.. That is to say, the target column specified in the SELECT statement can be one or multiple columns. When multiple columns are specified, multiple column names must be separated by commas. The table name or view name after the FROM clause is used to specify the name of the data table or view to be queried. [] The specified table name or view is optional. That is to say, the ROM statement can be followed by multiple table or view names. Separate multiple tables or views with commas. When the SELECT statement is used to query non-repeated records in a table, all rows that meet the conditions in the table are retrieved. Duplicate rows in the table are also queried. In practice, you do not want to see duplicate record rows in the results. To not display duplicate record rows in the query results, you must add a DISTINCT keyword to the SELECT statement to exclude duplicate Row Records in the query results. The format is as follows: select distinct target row [, target row,...] FROM table name or view name [, table name or view] use the column alias to query the query results displayed in the previous SELECT statement, the column name displayed in the query result is the name of the column defined in the data table specified in the SELECT statement. The names of the columns defined in the data table are generally in English. Sometimes, to better understand the information displayed in a column, you can use the column alias in the SELECT statement to change the name of the column displayed in the query results. Syntax format: SELECT target column [AS] column alias [, target column [AS] column alias…] FROM table name or view name [, table name or view]. The target column after the SELECT statement indicates the name of the specified column to be queried. The AS keyword is followed by the column alias to be used. The AS keyword is optional. The target column specified in the SELECT statement can be one or multiple columns. When multiple columns are specified, multiple column names must be separated by commas. The table name or view name after the FROM clause is used to specify the name of the data table or view to be queried. [] The specified table name or view is optional. That is to say, the ROM statement can be followed by multiple table or view names. Separate multiple tables or views with commas. SELECT stuID AS student ID, stuName AS student name, age AS age, sex AS gender, birth AS birth date FROM T_student in the query results, the column title is changed to an alias. Note: In a SELECT statement, you can use a space to replace the keyword AS. The space is followed by the name of the alias in the upper column. If a column alias contains spaces or special characters, such as periods (.), commas, semicolons, and colons, the alias must be enclosed by single quotation marks or double quotation marks. You can also use Arithmetic Operators to perform arithmetic operations on specified columns in the SELECT statement for queried records. Arithmetic Operators include addition (+), subtraction (-), multiplication (×), and Division (Division ). The priority of the SELECT statement is higher than that of the addition or subtraction operator. You can use arithmetic operations to obtain the specific results of the required columns. SELECT teaID AS instructor number, teaName AS instructor name, salary * 12 AS annual income FROM T_teacher Description: perform arithmetic operations in the SELECT statement and only change the displayed query results, the original values queried in the data table are not changed. When using a connector (|) to connect a field to a query using a SELECT statement, you sometimes need to connect two or more fields to display a more meaningful result. To connect multiple fields in the SELECT statement, you can use the "|" connector in the Oracle database. The following is an example of using a "|" connector. MYSQL Databases and Microsoft SQL server databases do not support "|" connector connection fields. To connect multiple fields, you can use the CONCAT function in MYSQL; use the plus sign (+) operator directly in SQL server. For NULL values in the database, if the column is not assigned a value and the column has no default value, the query result is NULL, that is, NULL. NULL does not represent space or 0.