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
  • 95
  • 2
  • 10

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
  • 20,688
  • 4
  • 50
  • 67
1

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

senseiwu
  • 4,617
  • 5
  • 23
  • 45
  • @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