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!
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!
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
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.
Shoot!
Thanks Troy. Forgot the wildcard....too fast on the keyboard, maybe :p
Thanks Guys! I appreciate it!
Is there a command to do this and search through an entire DATABASE? rather than just a table?
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!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.