mysqldatabasealiasrdbmsselect-query

How does the SELECT query work on multiple columns without using comma in between column names?


I'm studying SQL from w3schools SQL Tutorial

While studying the chapter SQL Aliases I come across following query :

SELECT CustomerName, Address+', '+City+', '+PostalCode+', '+Country AS Address
FROM Customers;

If you observe closely the query is fetching data from multiple columns, attaches the data from different columns with comma and show the data under aliased column name Address

If you want to see the working demo please go to the URL

http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_alias_column2&ss=-1

When we write normal query without alias for fetching data from different columns of a table we separate the column names with comma as follows :

SELECT CustomerName, Address, City, PostalCode, Country FROM Customers;

My doubt is as there are no commas have been used in a SELECT query for fetching data from different columns then how does it working?

The existing commas you see from the first query are for the purpose of connecting strings in output only.

Would someone please clear my doubt.

It would be better if someone could explain me from MySQL database point of view as I'm concerned with MySQL database system only.

Thank You.


Solution

  • Both are two different operators. The server parser recognizes an operator lets say , or +. And handles it appropriately. Column value is evaluated for both of them.