Avatar of sabecs
sabecs

asked on 

MySQL - split column contents into 2 seperate columns

Is there a way to spilt `contact` column from my users table below into `First_Name` & `Last_Name`?

Basically want to find the first space in `contact` column and split first section into   `First_Name`  and remaining into `Last_Name` ?

CREATE TABLE IF NOT EXISTS `users2` (
  `id` int(6) NOT NULL AUTO_INCREMENT,
  `email` varchar(90) DEFAULT NULL,
  `contact` varchar(40) DEFAULT NULL,
  `First_Name` varchar(120) DEFAULT NULL,
  `Last_Name` varchar(120) DEFAULT NULL,
  `Phone` varchar(30) DEFAULT NULL,
  `comments` text,
  `Business_Name` varchar(150) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 PACK_KEYS=0 AUTO_INCREMENT=1890 ;

--
-- Dumping data for table `users2`
--

INSERT INTO `users2` (`id`, `email`, `contact`, `First_Name`, `Last_Name`, `Phone`, `comments`, `Business_Name`) VALUES
(58, 'email2@gmail.com.au', 'Peter Testing', NULL, NULL, NULL, NULL, NULL),
(57, 'email4@gmail.com.au', 'Kathy Tristan', NULL, NULL, NULL, NULL, NULL),
(18, 'email5@gmail.com.au', 'Christoper Roberts', NULL, NULL, NULL, NULL, NULL);

Open in new window

MySQL Server

Avatar of undefined
Last Comment
sabecs

8/22/2022 - Mon