Jump to content

Select using Alias returns "0"

Recommended Posts

16 hours ago, Ingolme said:

The + operator in SQL only does mathematical additions. To concatenate words, use the CONCAT () function. 

Thanks, good to know. But how come the following code works as expected:

SELECT City + ' ' + Country AS Address FROM Customers;


Link to post
Share on other sites

Does that work? It depends on what kind of database you're using.

Here's a note from the tutorial page:


Note: To get the SQL statement above to work in MySQL use the following:

SELECT CustomerName, CONCAT(Address,', ',PostalCode,', ',City,', ',Country) AS Address
FROM Customers;



Link to post
Share on other sites

Assuming you're only using MySQL, you can also look up the documentation.  Here's the list of operators, note that for + that it only indicates that it is the addition operator:


Here's the list of string functions, this includes both concat and concat_ws.  The description for concat doesn't indicate that MySQL has another concatenation operator.


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...