MySQL Forums
Forum List  »  Newbie

Re: Help with using LIKE with variables
Posted by: Felix Geerinckx
Date: June 09, 2005 01:39PM

Adrian Sue wrote:

> I want something like:
> WHERE customer.name LIKE '%customer.nickname%'
> (finding customer's whose nicknames are short versions of their real names, for example)

> I am also using MS Access, if that might introduce notational diferences....


Don't know about MS Access, but in "pure" SQL you can do the following (but don't expect
stellar performance on large tables):

USE test;
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
nick VARCHAR(100)
);

INSERT INTO foo (name, nick) VALUES
('Johnaton', 'John'),
('Richard', 'Dick'),
('Peter', 'Pete');

SELECT
id, name, nick
FROM foo
WHERE
name LIKE CONCAT('%', nick, '%');

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: Help with using LIKE with variables
June 09, 2005 01:39PM


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.