简体   繁体   中英

How do I do a search call on one column of a table in MySQL?

I'd like to make a call on MySQL where I have a very big table. I'd like query to be able to search in one of there columns and find similar results. This is the sql query I have been trying:

SELECT gene FROM promoter where gene LIKE '%ccl5%' limit 10;

I included "limit 10" just to try it out. I have indexing on "gene" and it takes over 5-6 seconds for it to make this search. How can I search for a "phrase" in a specific coloumn with a least a decent speed?

I would also like to only get one of each result returned. If I search for 'ccl5' and it has been found several times, I get a list with all of 'ccl5' returned. I have tried using SELECT DISTINCT, but this causes the server to process the query for a long time.. I have yet to see it finish with this command.

If your values are really that big, you can try an InnoDB fulltext index :

ALTER TABLE promoter add fulltext index index_name(gene);

Then select it like this:

SELECT gene FROM promoter WHERE match (gene ) against ('ccl5');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM