Jump to content

[SOLVED] using CONCAT() in mysql 5


Tranquilraven

Recommended Posts

Hello everyone.

 

I think I have a brain freeze.  I am trying to use concat() in a sql querie in a PHP 6 document and it keeps throwing this exception:

mysql error number: 1064, you have an error in your sql syntax.  I am not seeing it.  Here is the code:

 

SELECT authors.author_id, authors.first_name, authors.family_name
CONCAT(authors.first_name,'  ', authors.family_name) AS author
FROM authors
ORDER BY authors.family_name, authors.first_name

 

Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/138932-solved-using-concat-in-mysql-5/
Share on other sites

I prefer starting each new column from the select list on a new line with a preceding comma; also, I like CONCAT_WS():

 

SELECT authors.author_id
, authors.first_name
, authors.family_name
, CONCAT_WS( ' ', authors.first_name, authors.family_name ) AS author
FROM authors
ORDER BY authors.family_name
, authors.first_name

 

Just my $0.02 -- IMHO, it makes it less likely to make these kinds of syntax errors.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.