1

How do i perform a search in mysql with a substring, instead of full string ?

i would like to return information from a search term e.g.. 'Wat' will return Waterloo and any other words with Wat in them ..

Karim
  • 415
  • 6
  • 14

2 Answers2

2

You can do it with a like:

SELECT * FROM YOUR_TABLE
WHERE YOURCOLUMN LIKE '%Wat%';

If you are only looking for something starting with Wat you can drop the first %

Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
1

You can use like '%Wat%', but if you want more sophisticated conditions, you may consider using rlike which leverages regular expressions

senseiwu
  • 5,001
  • 5
  • 26
  • 47
  • @KarimKawambwa you are welcome. Be careful though that searching using `like` does have an impact on performance. See http://stackoverflow.com/questions/2481528/mysql-like-performance-boost – senseiwu Oct 13 '13 at 18:30