MySQL Forums :: Newbie :: Comparing strings


Advanced Search

Comparing strings
Posted by: Roy Wood ()
Date: March 16, 2009 11:18AM

Ok, i have a problem I can't work out but i'll try to present it simply here.
Assume the table "Names".

FirstName, SecondName
Robert Smith
John Jones
Richard Robertson
Mike Richardson
Ian Stevenson

I need to write a query where by it selects all records where the First Name appears as part of any second name. the output should be

Robert Smith
Richard Robertson

Now, I know I can do
SELECT FirstName, LastName
FROM Names
WHERE LastName LIKE '%Richard%';

This will find all records where Richard appears as part of a last name. But I want it to work for any first name not just a specific one. i basicly need the last line to be something int he order of
WHERE LastName LIKE '%FirstName%';
only a version that works...

any ideas? this is driving me nuts...



Edited 1 time(s). Last edit at 03/16/2009 11:20AM by Roy Wood.

Options: ReplyQuote


Subject Written By Posted
Comparing strings Roy Wood 03/16/2009 11:18AM
Re: Comparing strings Peter Brawley 03/16/2009 11:28AM
Re: Comparing strings Roy Wood 03/16/2009 11:38AM
Re: Comparing strings Peter Brawley 03/16/2009 12:18PM
Re: Comparing strings Roy Wood 03/17/2009 09:33AM
Re: Comparing strings Peter Brawley 03/17/2009 09:37AM
Re: Comparing strings Roy Wood 03/17/2009 10:01AM
Re: Comparing strings Peter Brawley 03/17/2009 10:44AM
Re: Comparing strings Roy Wood 03/17/2009 10:51AM
Re: Comparing strings Peter Brawley 03/17/2009 10:59AM
Re: Comparing strings Roy Wood 03/17/2009 11:04AM
Re: Comparing strings Jay Alverson 03/17/2009 12:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.