MySQL splitting a string with a delimiter and taking the 1st value and update
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok it will do the last_name like I want now, however I want it to update the table: I get a syntax error, so I think I am being too clever for MySQL.. php you can get away with murder
update instuctors WHERE last_name = SELECT DISTINCT SUBSTRING_INDEX(instructor, ', ', 1) FROM instructors;
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78
Rep:
1st, maybe wanna think about posting actual phone numbers on the net. This page will be archived and be around forever, maybe use some asterisks.
2nd, I have a suggestion, but make a copy of the data and work on that. I haven't used mysql in a long time, and I have no idea if this will work. What you're doing there is adding new rows, when it sounds like you need to be updating rows.
Try:
Code:
UPDATE instructors SET last_name=SUBSTRING_INDEX(instructor, ", ", 1), first_name=SUBSTRING_INDEX(instructor, ", ", -1)
WHERE instructor IS NOT NULL;
1st, maybe wanna think about posting actual phone numbers on the net. This page will be archived and be around forever, maybe use some asterisks.
2nd, I have a suggestion, but make a copy of the data and work on that. I haven't used mysql in a long time, and I have no idea if this will work. What you're doing there is adding new rows, when it sounds like you need to be updating rows.
Try:
Code:
UPDATE instructors SET last_name=SUBSTRING_INDEX(instructor, ", ", 1), first_name=SUBSTRING_INDEX(instructor, ", ", -1)
WHERE instructor IS NOT NULL;
UPDATE students SET email = LOWER(CONCAT(LEFT(SUBSTRING_INDEX(first_name, ", ", 1),1),SUBSTRING_INDEX(last_name, ", ", -1),"@shoes.ca")) WHERE first_name IS NOT NULL;
Gotter Made it lowercase, shifted letters and concatenated on the email prefix. Thanks Man
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.