0

This is going to sound crazy - but is there any way to to a search for a phrase of text within my SQL database?

(I am obviously not very knowledgeable) except on how to get there! :)

Thanks for the help!

3
Contributors
5
Replies
6
Views
12 Years
Discussion Span
Last Post by Troy
0
SELECT * FROM table_name WHERE field_name = 'some text'

...will return rows where 'field_name' is exactly = 'some text'

SELECT * FROM table_name WHERE field_name LIKE 'some text'

...will return wors where 'some text' is included in 'field_name'

To include more fields in the search use 'OR'

SELECT * FROM table_name WHERE field1_name = 'some text' OR field2_name = 'some text
0

madmital's post is good except one mistake.

SELECT * FROM table_name WHERE field_name LIKE 'some text'

...will return wors where 'some text' is included in 'field_name'

Should be

SELECT * FROM table_name WHERE field_name LIKE '%some text%'

Notice the % signs? They act as wildcards meaning anything before or after.

0

Thanks Guys! I appreciate it!

Is there a command to do this and search through an entire DATABASE? rather than just a table?

0

The way I've done that in the past is tediously building queries that check for the value in every text like column of every table. However, I'm recently made aware of mysql's MATCH/AGAINST. I have no experience with it, so I can't help you with the code, but check out http://dev.mysql.com/doc/mysql/en/fulltext-search.html

Apparently, if your tables are setup with fulltext indexes, then you can use MATCH/AGAINST to find text across multiple columns and tables---like you want. I hope somebody with more experience replies to this thread with a query example. Also, if you work out your solution, be sure to post a follow up here for us to learn. Thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.