How to use alias in SQL

Source: Internet
Author: User

Has been very strange, do not know why SQL alias how to use, last saw thinkphp in the explanation, why the database in use sometimes like to change the name of the use,

Because yesterday to participate in the company's database development Engineer's written test, today to review SQL, see the role of SQL Alias, the following is his/her role in the use of Alias

To know when he used it was better.

Let's say we have two tables: "Persons" and "Product_orders", respectively. We assign them the alias "P" and "Po", respectively.

Now we want to list all orders for "John Adams".

We can use the following SELECT statement:

1 SELECT Po. OrderID, P.lastname, P.firstname2 from as as po3WHERE p.lastname='Adams' and P.firstname='  John'

SELECT statements that do not use aliases:

1 SELECT Product_orders.orderid, Persons.lastname, Persons.firstname 2  from Persons, Product_orders 3 WHERE Persons.lastname='Adams' and persons.firstname= ' John '

How to use alias in SQL

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.