MySQL (iii) DQL basic query

Source: Internet
Author: User

1. Grammar

SELECT what to query from the table name;

Similar to Java: System.out.println (something to print);

2. Features

① The result of a select query is a virtual table, not a real existence.

② to query can be a constant value, can be an expression, can be a field, can be a function.

3. Querying a single field in a table

SELECT last_name from Employees;

4. Querying multiple fields in a table

SELECT Last_name,salary,email from Employees;

5. Querying all fields in the table

SELECT * FROM Employees;

6. Query constant Value

SELECT ' John ';

7. Query expression

SELECT 100%98;

8. Query function

SELECT VERSION ();

9, from the alias

① Easy to understand

② If the field you want to query has the same name, you can distinguish it by using an alias

Mode one: Use as

SELECT Last_Name as surname, first_name as name from employees;

Way two: Use spaces

SELECT last_name Surname, first_name name from employees;

Case: Query salary, display results as out put, enclosed in double quotes

Select salary as "out put" from employees;

10, go to Heavy

Case: Querying all the department numbers involved in the employee table

SELECT DISTINCT department_id from employees;

11, + Number of the role

The + sign in Java:

① operator with two operands of numeric type

② connector, as long as one operand is a string

MySQL in the + number:

There is only one function: operator

Select 100+90; Two operands are numeric, then add operation

Select ' 123 ' +90; if one of the characters is a character type, try to convert the character value into a numeric type, and if the conversion succeeds, continue with the addition operation

Select ' John ' +90; Converts a character value to 0 if the conversion fails

Select Null+10; As long as one of the two is null, the result must be null

12, CONCAT

Case: Query employee name and last name concatenated into a field and displayed as name

SELECT CONCAT (last_name,first_name) as name from employees;


If you concatenate one more empty field, the result is null


Workaround, use the Ifnull function


MySQL (iii) DQL basic query

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.