I have a table employee with thousands data. I need search particular string from this table. How to write query for that Please help me Thanks in advance
Asked
Active
Viewed 159 times
0
-
3add your table definition – Mahesh Madushanka Jul 03 '16 at 03:42
-
2...and show us some sample data please. – Tim Biegeleisen Jul 03 '16 at 04:00
-
1Possibly related question [Extract a search string in context](http://stackoverflow.com/q/6221821/4519059) or [How can I manipulate MySQL fulltext search relevance to make one field more 'valuable' than another?](http://stackoverflow.com/q/547542/4519059) ;). – shA.t Jul 03 '16 at 06:32
2 Answers
2
Here's an example
SELECT field_name
FROM table_name
WHERE = 'value'

shA.t
- 16,580
- 5
- 54
- 111

Melchizedek
- 1,057
- 17
- 29
0
If one (or possibly more) column has a bulk text you can use full-text search ability of mysql (5.6 and above) to do that. It will speed up search operation very much. The Documentation is here.
Sample:
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
) ENGINE=InnoDB;
SELECT id, title, body,
MATCH (title,body) AGAINST ('database' IN BOOLEAN MODE) AS score
FROM articles ORDER BY score DESC;

Mostafa Vatanpour
- 1,328
- 13
- 18