MySQL Basic query

Source: Internet
Author: User
Tags mysql in

#进阶1: Basic Query
/*
Grammar:
Select: Query list from table name;

Similar to: System.out.println (something printed);

Characteristics:
1. The query list can be: A field in a table, a constant value, an expression, a function
2, the result of the query is a virtual table
*/
Use MyEmployees

#1, querying a single field in a table
SELECT last_name from Employees;

#2, querying multiple fields in a table
SELECT Last_name,salary,email from Employees;

#3, querying all fields in a table
SELECT
' First_Name ',
' Last_Name ',
' Email ',
' Phone_number ',
' job_id ',
' Salary ',
' Commission_pct ',
' manager_id ',
' HireDate '
From
Employees;

#方式二
SELECT * FROM Employees

#查询常量值
SELECT 100;
SELECT ' John ';

#查询表达式
SELECT 100%98;

#查询函数
SELECT VERSION ();

#7, aliases
/*
1. Easy to understand
2. If the field you want to query has the same name, use an alias to differentiate
*/
#方式一: Using as
SELECT 100%98 as results;
SELECT Last_Name as surname, first_name as name from employees;
#方式二: Use spaces
SELECT last_name Surname, first_name name from employees;

#案例: Query salary, display results as Out_put
Select Salary "Out_put" from employees;

#8, go heavy

#案例: Query All department numbers involved in the employee table
SELECT DISTINCT department_id from employees;

The function of #9 and + number
/*
The + sign in Java
1, Operator: Two operands are numeric
2, connector: As long as there is 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; one of them is a character type, attempting to convert a character value into a numeric type
If the conversion succeeds, continue with the addition operation
Select ' John ' +90; convert the character to 0 if the conversion fails

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

*/

#案例: Query employee name and last name concatenated into a field and displayed as name
SELECT CONCAT (' A ', ' B ', ' C ') as result;
SELECT CONCAT (' last_name ', ' first_name ') as name from employees;

MySQL 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.