简体   繁体   中英

Sql Query to fetch a matching rows for two criteria

I have the fields called language and the values are like hindi,english .

So if I select hindi and english , I used like clause so this rows comes in the result.

But if I use:

SELECT * FROM  `rr` WHERE rr LIKE  '%english,hindi%' LIMIT 0 , 30

This row won't come in the result.

So can any one please help me to solve this ?

Thanks in advance.

BOOLEAN MODE may help you

SELECT * FROM rr WHERE MATCH (rr) 
     AGAINST ('+english +hindi' IN BOOLEAN MODE) LIMIT 0 , 30;

Usage :

SELECT * FROM tablename WHERE MATCH (col1, col2) AGAINST ('string to be searched')

Basing it off of the example here

MySQL can perform boolean full-text searches using the IN BOOLEAN MODE modifier. With this modifier, certain characters have special meaning at the beginning or end of words in the search string. In the following query, the + and - operators indicate that a word is required to be present or absent, respectively, for a match to occur. Thus, the query retrieves all the rows that contain the word “val1” but that do not contain the word “val2”:

mysql> SELECT * FROM TABLE WHERE MATCH (COL1,COL2)
    -> AGAINST ('+val1 -val2' IN BOOLEAN MODE);

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