Exact Match
Anonymous Monk
created: 2006-06-02 06:16:52
All,
Require your help on this. Following values are stored in the column "description_column" in one of the tables called description_table. The values are
"My name is Robert Jr." and another value is
"Robert is my name." .

So to select "Robert Jr." from the table we issue the following query,
Select * from description_table
where 'Robert Jr.' like '%'+description+'%'

But the query returns both the values "My name is Robert Jr." and "Robert is my name.", though we only want "My name is Robert Jr." to be returned.

Is it possible in PERL to look for the exact match after the query returns both the rows, so only "Robert Jr." is matched and "Robert" is not selected.

Regards
Re: Exact Match
created: 2006-06-02 06:28:12
I might be missing something here, but I think your SQL statement is incorrect. Shouldn't it be

select * from description_table where description like '%Robert Jr.%'
Update: Or even, since you want an EXACT match:
select * from description_table where description = 'Robert Jr.'
[id://149675|"What should it profit a man, if he should win a flame war, yet lose his cool?"]
Re: Exact Match
created: 2006-06-02 06:30:11
[Anonymous Monk],

Perhaps I am not understanding the question you trying to ask, would you not be better doing something like:
select * from description_table 
where description column = 'My name is Robert Jr.'

Update: The answer above is based purely on the 'we only want "My name is Robert Jr." to be returned.'

Please read the [PerlMonks FAQ] and [id://174051] if you have not done so already.

Martin
Re: Exact Match
created: 2006-06-02 06:31:10
erm, I think you have your SQL where clause back-to-front. Why don't you try:
SELECT * FROM description_table
    WHERE description_column LIKE '%Robert Jr%';
Re: Exact Match
created: 2006-06-02 06:31:24

Rather than working around the problem in Perl, your time would be better spent getting your SQL to return the correct data.

You don't say which database system you are using, but I think you want something like:

select *
from   description_table
where  description_column like '%Robert Jr.%';

To be honest, I'm surprised that your current SQL even compiles. I assume it's preprocessed in some way before it's sent to the database.

Note: Of course select * is almost always bad practice - you should replace * with the list of columns that you're interested in.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Re^2: Exact Match
created: 2006-06-03 02:06:36
Thanks for the update.. I will try your suggestions and get back.. Regards

perlmonks.org content © perlmonks.org and Anonymous Monk, davorg, Joost, marto, McDarren

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03