Solved

concact in mysql

Posted on 2004-09-29
8
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 50 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using cfstoredproc to return query data 2 69
mysql db 3 95
MySQL to get Limited value from each category. 6 40
SQL Function 4 38
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Creating and Managing Databases with phpMyAdmin in cPanel.

734 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