Solved

concact in mysql

Posted on 2004-09-29
8
439 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 50 total points
Comment Utility
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
Comment Utility
I tried the same select and it worked fine...
0
 
LVL 13

Expert Comment

by:cLFlaVA
Comment Utility
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
 
LVL 26

Expert Comment

by:ushastry
Comment Utility
try this..
 
Select concat(LastName,',',ForeName)   AS NewNames from Employees;
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 13

Expert Comment

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

Expert Comment

by:ushastry
Comment Utility
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
Comment Utility
Ahh gotcha - no biggie...

:)
0
 
LVL 3

Expert Comment

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

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now