Solved

mysql subquery (query for function parameter)

Posted on 2014-01-10
2
252 Views
Last Modified: 2014-02-11
Not sure if this is ok to combine so many things...

If I have a table with columns:
firstname
lastname

the name "experts exchange" in firstname.

I want to search for the space, and put everything after into `lastname`. ie(firstname:experts  lastname:exchange)

Logically, this is what I would want.
update table set `lastname` = substr(`firstname`, (SELECT instr(`firstname`, ' ') FROM table));

(even that though would include the space, so I would want instr + 1. Or I could do a second pass to remove the leading space afterwards....

Thanks in advance!
0
Comment
Question by:ststesting
2 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 250 total points
Comment Utility
You could use SUBSTRING_INDEX(lastname, " ", -1) to find the last space.

So then you would select  SUBSTRING(lastname, SUBSTRING_INDEX(lastname," ",-1)+1) to get everything following the last space.
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 250 total points
Comment Utility
You can try this.
Update test
Set lastname = trim(substring_index(firstname,' ',-1));

Open in new window


http://sqlfiddle.com/#!9/785c3/1
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

13 Experts available now in Live!

Get 1:1 Help Now