MySQL Forums
Forum List  »  Newbie

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

Written By
Comparing strings
March 16, 2009 11:18AM
March 16, 2009 11:28AM
March 16, 2009 11:38AM
March 16, 2009 12:18PM
March 17, 2009 09:33AM
March 17, 2009 09:37AM
March 17, 2009 10:01AM
March 17, 2009 10:44AM
March 17, 2009 10:51AM
March 17, 2009 10:59AM
March 17, 2009 11:04AM
March 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.