Aliases must be used in SQL queries.

Source: Internet
Author: User

Aliases must be used in SQL queries.

When do I need to use the table alias in SQL queries?

I encountered the problem of using the table alias when I wrote MySQL today. I 'd like to repeat it here.

1. The table name is very long.

Select * from www_baidu_user where www_baidu_user.id = 1;

And

Select * from www_baidu_user u where u. id = 1;

The query results are the same, but the second table alias is more concise. Similarly, the field alias works the same way.

2. When aliases are required

As follows:

1)

Select * from (select * from table1) as t1

This is the alias used to directly query all data from a subquery.

2)

Select B. name id, a. job, a. sex from A left outer join B B on B. id = a. id

This is used to query data in one or more columns. For example, if Table A does not have the name field, the table name or table alias must be included in the query. This is often used in connection queries.

The preceding section describes the alias used in SQL queries. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.