vitruvius Posted May 31, 2017 Share Posted May 31, 2017 Hi, I am trying to learn basics of the SQL and following the tutorials on w3schools. Yesterday I was reading SQL Aliases and "Trying it myself". The following code returns 10 rows, each of them being zero. Am I missing something? SELECT FirstName + ' ' + LastName AS Name FROM Employees; Thanks. Link to comment Share on other sites More sharing options...
Ingolme Posted May 31, 2017 Share Posted May 31, 2017 The + operator in SQL only does mathematical additions. To concatenate words, use the CONCAT () function. Link to comment Share on other sites More sharing options...
vitruvius Posted June 1, 2017 Author Share Posted June 1, 2017 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 comment Share on other sites More sharing options...
Ingolme Posted June 1, 2017 Share Posted June 1, 2017 Does that work? It depends on what kind of database you're using. Here's a note from the tutorial page: Quote 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 comment Share on other sites More sharing options...
justsomeguy Posted June 1, 2017 Share Posted June 1, 2017 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: https://dev.mysql.com/doc/refman/5.7/en/non-typed-operators.html 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. https://dev.mysql.com/doc/refman/5.7/en/string-functions.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now