Jump to content

[SOLVED] Merging fields


rfleming

Recommended Posts

Hi all,

My current project requires me to return three VARCHAR(45) fields back in a resultset containing 1 VARCHAR.

The code needs to return FIRST_NAME MIDDLE_NAME LAST_NAME as one string. I have tried using the + operator in the query statement to no luck. it just outputs a bunch of 0's. I have tried searching google but no luck. Any ideas?

Version: 5.0

The table's CREATE code

CREATE TABLE `people` (
  `PEOPLE_ID` int(10) unsigned NOT NULL auto_increment,
  `LAST_NAME` varchar(45) NOT NULL,
  `FIRST_NAME` varchar(45) NOT NULL,
  `MIDDLE_NAME` varchar(45) NOT NULL,
  PRIMARY KEY  (`PEOPLE_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1

I think that is all the info i have on it. Yell at me if i forgot anything.

Thank you,

 

Link to comment
Share on other sites

Use the MySQL concat_ws function.  This will allow you to concatenate multiple fields with a separator of choice, which in your case is space.

 

SELECT CONCAT_WS(' ', FIRST_NAME, MIDDLE_NAME, LAST_NAME) AS NAME FROM people

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.