简体   繁体   中英

How to search for numbers with MATCH() AGAINST()

I have a column named: name , type: text , FULLTEXT index

and I try to find an IP address in the column name with this query:

SELECT * FROM `data` WHERE  MATCH(ip) AGAINST ('127.0.0.1')

but I got 0 as a result , it worked only with letter, with number it does not. How to fix it?

try SELECT * FROM data WHERE ip LIKE '%127.0.0.1%'

or if ip address is in name column, than SELECT * FROM data WHERE name LIKE '%127.0.0.1%'

What does the ip field contain? Is it a single IP address or a load of them?

If it's just a single address, you don't need to use MATCH or LIKE or any other specialist query; just use = . ie:

SELECT * FROM data WHERE ip = '127.0.0.1'

If it's more than one IP address in there per record, I suggest you consider splitting it out into a separate cross-reference table, as it will make things a lot easier to manage when you need to do search queries like this. Then the answer again reverts to just use = , with a join on the IP table.

SELECT * FROM data d
INNER JOIN ipAddresses i on i.dataID=d.id
WHERE i.ip = '127.0.0.1'

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