0

So I want to take the first letter of the first name and all of the last name, add them together and make that the person's username.

I was using CONCAT() and I keep getting an unexplained syntax error from MySQL.

I have:

SELECT 
CONCAT(left(first_name, 1), left(last_name)) username
FROM survey_responders;

And all I get is "Syntax Error" as my error. What am I doing wrong?

1
  • Doesn't LEFT require two parameters? What happens when you use left (last_name,1) instead of left(last_name)? Commented Mar 23, 2015 at 19:34

2 Answers 2

1

You are missing the second argument for left(last_name), but I don't even think you need that call to left since you want the whole thing. So:

SELECT 
CONCAT(left(first_name, 1), last_name) username
FROM survey_responders;
Sign up to request clarification or add additional context in comments.

Comments

0

The function left is good but substr is more efficient, try this instead:

select concat(substr(first_name, 1, 1), last_name) username FROM survey_responders;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.