Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (4k points)

I'm not professional in query writing, but wrote many from the time I began MySQL. Recently I noticed there is no need to type AS keyword in name aliasing.

SELECT name AS n

equals to

SELECT name n

However I know that this ability is out from years ago. I've 2 questions around this subject:

  1. Is AS keyword redundant?
  2. Sometimes ago when I encountered with a custom query on a website with having no AS in aliasing, that its executing made MySQL service down, I changed the way of name aliasing with adding AS keyword and this little change made it work!

    What was the problem here?

1 Answer

0 votes
by (8.7k points)
edited by

Let’s Discuss what ‘AS’ does to the SQL queries

So ‘As’ keyword is used to create an alias or assign a temporary name to a table, or a column in a table.

Have look at the below example:

Use of ‘AS’ keyword:

SELECT CONCAT(,', ',first_name) AS full_name   FROM mytable

ORDER BY full_name;

Without the ‘AS’ keyword:

SELECT CONCAT(last_name,', ',first_name) full_name   FROM mytable

ORDER BY full_name;

A problem occurs when you missed out on the comma between the select statement, due to which MYSQL interprets the second one as an alias name. It’s optional and one’s personal choice to use the ‘AS’ keyword but it is always considered to be a good practice to use it in a query.

Intellipaat provides SQL Certification Course to make you industry ready.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 20, 2021 in SQL by RohitSingh (2.6k points)
0 votes
1 answer
asked Jan 1, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 27, 2020 in SQL by Appu (6.1k points)

Browse Categories

...