Solved

How do you search for you one word in field?

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

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…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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