Skip to Content

Solved: What does the SQL/MySQL Aliases syntax do and mean?

Question: Refer to the below SQL statement for syntax highlighted in bold.

FROM provider_payments t1
WHERE = (SELECT MAX( provider_payments t2 WHERE t2.account_id = t1.account_id)

Normally after the FROM clause, we would see “tablename1, tablename2”, but here we can not see a comma behind the table name. Read on below explanation to understand what does SQL aliases syntax do and mean.

Explanation #1: The WHERE clause is built up out of a subquery. The highest ID from provider_payments table is selected which fits the accound_id. As both queries reflect the provider_payments table there may be several lines for one account_id and the query takes the one which the highest ID.

Explanation #2: t1 is the table alias for the provider_payments table. Table alias it’s a way to create a shortcut when having to add the table name to columns like

Otherwise, you would have to repeat the long table name:

It is also written as: FROM provider_payments as t1

In some SQL’s, the ‘as’ is optional. Refer to W3Schools > SQL > SQL Aliases for more information.

Alex Lim is a certified IT Technical Support Architect with over 15 years of experience in designing, implementing, and troubleshooting complex IT systems and networks. He has worked for leading IT companies, such as Microsoft, IBM, and Cisco, providing technical support and solutions to clients across various industries and sectors. Alex has a bachelor’s degree in computer science from the National University of Singapore and a master’s degree in information security from the Massachusetts Institute of Technology. He is also the author of several best-selling books on IT technical support, such as The IT Technical Support Handbook and Troubleshooting IT Systems and Networks. Alex lives in Bandar, Johore, Malaysia with his wife and two chilrdren. You can reach him at [email protected] or follow him on Website | Twitter | Facebook

    Ads Blocker Image Powered by Code Help Pro

    Your Support Matters...

    We run an independent site that is committed to delivering valuable content, but it comes with its challenges. Many of our readers use ad blockers, causing our advertising revenue to decline. Unlike some websites, we have not implemented paywalls to restrict access. Your support can make a significant difference. If you find this website useful and choose to support us, it would greatly secure our future. We appreciate your help. If you are currently using an ad blocker, please consider disabling it for our site. Thank you for your understanding and support.