dbTalk Databases Forums  

Checking if a String match to a list of values.

comp.databases.mysql comp.databases.mysql


Discuss Checking if a String match to a list of values. in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Leandro Costa
 
Posts: n/a

Default Checking if a String match to a list of values. - 09-02-2011 , 09:56 AM






Hi everybody, I'm new on the list, this is my first topic.

I was wondering if it's possible to check for a string ( a url, name, etc ) matchs with a list of values into a table.

Eg.: table myvalues(int id, varchar value);

imagine I have a few rows in this tables and I have the string "my foo string for test".

I would like to check if the string match with some row in the table myvalues, for ex. a row like (1, 'foo') should match.

Thanks for your attention.

Reply With Quote
  #2  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: Checking if a String match to a list of values. - 09-02-2011 , 10:09 AM






Leandro Costa wrote:
Quote:
Hi everybody, I'm new on the list, this is my first topic.

I was wondering if it's possible to check for a string ( a url, name, etc ) matchs with a list of values into a table.

Eg.: table myvalues(int id, varchar value);

Of course it is.

Quote:
imagine I have a few rows in this tables and I have the string "my foo string for test".

I would like to check if the string match with some row in the table myvalues, for ex. a row like (1, 'foo') should match.

select count(id) from myvalues where value like '%my foo string for
test%' would get you something sane.

e.g. on a table that records the whois results of people accessing one
of my sites..

select count(id) from ipdata where whois like'%microsoft%';
+-----------+
Quote:
count(id) |
+-----------+
289 |
+-----------+

tells me that 289 different IP addresses that belong to Microsoft
registered domains (hotmail mostly) have accessed the site.



> Thanks for your attention.

Reply With Quote
  #3  
Old   
Leandro Costa
 
Posts: n/a

Default Re: Checking if a String match to a list of values. - 09-02-2011 , 10:41 AM



Natural Philosopher, thanks for you answer, but this I know how to do .

What I want is, I have the string: "my foo string for test".

I have the table myvalues like:


1, bar
2, aaa
3, foo
4, bbb
5, ccc

I want to do a query that tells my that the row 3 ( 3,fool ) matchs to my string: "my foo string for test"


I found the solution, it's like:

select * from myvalues where "my foo string for test" like concat('%',value,'%');

in this example it will output:

3, fool.


Thanks for your attention.

If someone can think some better way to do the same, I would be glad.

Reply With Quote
  #4  
Old   
Peter H. Coffin
 
Posts: n/a

Default Re: Checking if a String match to a list of values. - 09-02-2011 , 01:49 PM



On Fri, 2 Sep 2011 08:41:25 -0700 (PDT), Leandro Costa wrote:
Quote:
Natural Philosopher, thanks for you answer, but this I know how to do .

What I want is, I have the string: "my foo string for test".

I have the table myvalues like:


1, bar
2, aaa
3, foo
4, bbb
5, ccc

I want to do a query that tells my that the row 3 ( 3,fool ) matchs to
my string: "my foo string for test"
Full-text searches will do this. See section 11.9 and especially 11.9.2
in the manual

--
_ o
> /)

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.