Solved

How do you search for you one word in field?

Posted on 2011-09-18
4
239 Views
Last Modified: 2012-05-12
I need to search for a particular word in MYSQL.  I want to find any record with that word in a particular field.  The field can have other words, but I want to find all records with this particular word.

Additionally ... This mysql is running on my Linux dedicated box (at a co-lo) -- I currently use community edition of SQLyog to query (and modify small portions) of the database.  I'd be interested in other software that I could use for this same purpose.
0
Comment
Question by:U_S_A
  • 3
4 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 36558122
This is typically done with LIKE and the wildcard "%".

% - matches 0 or more chars (like .* in regex)
? - matches a single character

You could also use the REGEXP operator, but it is typically much slower.
SELECT *
FROM mytable
WHERE some_field LIKE "%someword%'
;

Open in new window

0
 
LVL 3

Accepted Solution

by:
libby9284 earned 50 total points
ID: 36558124
Does this help?

MySql to get all rows containing hello in column mycolumn in table mytable

select * from mytable where mycolumn like '%hello%';

Open in new window

0
 
LVL 23

Expert Comment

by:nemws1
ID: 36558128
Ooops!  Sorry - the match single character in LIKE is *not* ? - it is an underscore.

For example, in this query, "something" can appear anywhere in "some_field", but only rows that also end in "CODE" followed by two characters will match.
SELECT *
FROM mytable
WHERE some_field LIKE "%something%CODE__"
;

Open in new window

0
 
LVL 23

Expert Comment

by:nemws1
ID: 36558436
Yeah... that's what I had said....
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now