Solved

How do you search for you one word in field?

Posted on 2011-09-18
4
242 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

807 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