3

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

1
  • 3
    sql-server is not the right tag if this is for mysql. sql-server is the tag for Microsoft SQL Server. Commented Jun 14, 2011 at 12:08

4 Answers 4

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

This should work always

Sign up to request clarification or add additional context in comments.

2 Comments

SELECT DISTINCT concat(member_Firstname,'',member_Lastname) As Name FROM members WHERE Name Like 'a%' but i got the error like this Unknown column 'Name' in 'where clause' would you pls help
you cannot use alias names for conditions use complete function like ... where concat(member_Firstname,'',member_Lastname) like 'a%'
2

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

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

Comments

1

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

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

Comments

0
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); 

2 Comments

SELECT DISTINCT concat(member_Firstname,'',member_Lastname) As Name FROM members WHERE Name Like 'a%' i got error when i am executing the this statement saying that " Unknown column 'Name' in 'where clause' "
You have to write: WHERE concat(member_Firstname,'',member_Lastname) LIKE 'a%' INSTEAD OF WHERE NAME LIKE 'a%'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.