MySQL field as detailed and instance code _mysql

Source: Internet
Author: User
Tags aliases

MySQL Field uses as

In MySQL, a select query can use the AS keyword to alias the field of a query, which is used as the column name for an expression, and the alias can be used in statements such as group By,order by or having. For example:

SELECT CONCAT (last_name, ', ', first_name) as Full_name from MyTable order by Full_name;

When used with a select query, the AS keyword is optional. The above SQL statement can also be written like this:

SELECT CONCAT (last_name, ', ', first_name) Full_name from MyTable order by Full_name;

Because as is optional, if you forget to enter a comma between the query fields, MySQL will use the second field as the alias for the first field. For example, COLUMNB is considered an alias for columna in the following SQL statement:

SELECT Columna columnb from MyTable;

For this reason, it is recommended that you add the AS keyword when using aliases.

MySQL table uses as

A table can specify aliases using the Tbl_name as Alias_name or tbl_name alias_name:

SELECT T1.name, t2.salary from employee as T1, info as t2 WHERE t1.name = t2.name;

SELECT T1.name, t2.salary from employee T1, info T2 WHERE T1.name =t2.name;

Look at one more example:

SELECT Employee.first_name, Job.title, Duty.task from employee left join job on employee.id = Job.id left join duty on EMP Loyee.id = Duty.id WHERE (job.title = ' Manager ');

Through this article I hope you can understand the knowledge of MySQL as information, thank you for the support of this site!

Related Article

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.