5. Basic query operation

Source: Internet
Author: User
Tags arithmetic arithmetic operators

My study notes, the records are my own thought of the knowledge point, may later look at the time to turn the book, but can be used to locate the exact book of the location of the sample, reduce the time to find the book again, conducive to the construction of their own knowledge system. Self-Transcendence

5th Chapter Basic Query operation

5.1 Querying all columns of records

Select distinct * FROM table name, view name

* represents all columns, from which you can have up to 256 tables or view names, separated by ",".

* location can be replaced with field names, multiple field names with "," separated, several field names to check a few columns.

Distinct keyword, which is used to remove duplicate row data when the specified column is checked. (primary key is always different, * cannot be used)

The field name followed by as as gives the field an alias.

5.2 Arithmetic operations on the records of a query

You can use arithmetic operators to +-*/,*/precedence over +-in a SELECT statement.

Example: Check the teacher's annual income

Select teacher ID, teacher monthly income *12 as teacher annual income from teacher table

The operation in select does not change the original value, only changes the result of the query that is displayed.

5.3 Using Connectors | | Connection fields

Two fields can be used | | into a new string.

When connecting a field, the type of two fields should be the same, and if different, the system will have an error. If you need to include a character in a connected field or a value of a date type, you need to wrap the value of that character or a date type with single quotes.

MySQL and SQL Server do not support | | Select Student Name | | Teacher Name

MySQL uses the concat function select concat (student name, teacher name)

SQL Server uses the + number select Student Name + teacher Name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.