user682417
user682417

Reputation: 1518

sql columns adding

I am trying to add two columns as one column by using this statement

SELECT (member_Firstname+''+member_Lastname) AS Name FROM members

but it gives all 0 values in mysql workbench

Upvotes: 3

Views: 111

Answers (4)

AjayR
AjayR

Reputation: 4179

SELECT concat(member_Firstname,'',member_Lastname) AS Name FROM members;

This should work always

Upvotes: 7

Spudley
Spudley

Reputation: 168685

Adding is for numbers; for joining strings, use concat()

SELECT CONCAT(string1,string2,string3,etc) FROM table

Upvotes: 1

Talha Ahmed Khan
Talha Ahmed Khan

Reputation: 15433

SELECT CONCAT(CAST(int_col AS CHAR), char_col);

CONCAT() returns NULL if any argument is NULL.

So for the example

SELECT CONCAT(member_Firstname, member_Lastname);

Upvotes: 0

UltraCommit
UltraCommit

Reputation: 2276

I think that in MySQL you should use CONCAT, as follows:

mysql> SELECT CONCAT('My', 'S', 'QL'); -> 'MySQL'

Upvotes: 2

Related Questions