Reputation: 13
I'm trying to use the concatenation operator( || ) to select two columns as one in MySQL. But, the output is not coming.
The table 'emp' has four columns named -> eid (int), fname (varchar(20)), lname (varchar(20)) and salary (float).
3 records are entered into the table emp.
Now, when I'm trying to execute the following query:
SELECT fname || lname as Name from emp;
The result is coming out to be:
Name 0 0 0
instead of the names like "John Doe", etc.
Upvotes: 0
Views: 38
Reputation: 94662
Use the CONCAT()
function
SELECT concat(fname, ' ', lname) as Name from emp;
In MySQL the ||
is a logical OR, hence the result you are getting
Upvotes: 1