Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

concact in mysql

Posted on 2004-09-29
8
Medium Priority
?
447 Views
Last Modified: 2012-06-21
I'm using mysql database in windows.
I'm getting an error when I try this command:
Select concat(LastName, ',', ForeName)AS NewNames from Employees;

Everything is right in the database (names, fields)!
I don't know what is wrong in the code above?
Is there another way to write this SQL command?Thanks for any help.
0
Comment
Question by:viktor999
  • 4
  • 2
  • 2
8 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 150 total points
ID: 12179931
Two things to try:

The simple "+" Concatenation:
SELECT LastName + ', ' + ForeName AS NewNames FROM Employees;

The CONCAT_WS() function (concat with separator):
SELECT CONCAT_WS(', ', LastName, ForeName) AS NewNames FROM Employees;
0
 
LVL 3

Expert Comment

by:steve918
ID: 12179971
I tried the same select and it worked fine...
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12180052
Also, what is your error?  Is it "you have an error in your MySQL Syntax near 'AS NewNames from Employees;'?

Because if that's the error, it's because you don't have a space between your ) and your AS.  I had originally assumed that was just a typo on ee, I could be wrong though.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 26

Expert Comment

by:Umesh
ID: 12180076
try this..
 
Select concat(LastName,',',ForeName)   AS NewNames from Employees;
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12180137
How is that any different from what has already been said?
0
 
LVL 26

Expert Comment

by:Umesh
ID: 12180190
I didn't see it (I think u have submitted when I was typing.. that time how can I see updated page.. after posting only I saw)
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12180239
Ahh gotcha - no biggie...

:)
0
 
LVL 3

Expert Comment

by:steve918
ID: 12180659
the AS worked fine for me as above concat()AS works fine on mysql 3.23 w/ Fedora Linux
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question