开发者

MySQL text search example

开发者 https://www.devze.com 2023-02-20 01:36 出处:网络
I have a table called table1 with 3 columns, a, b, and c. b is varchar(600), say, and I wish to return the int from column a, say.

I have a table called table1 with 3 columns, a, b, and c.

b is varchar(600), say, and I wish to return the int from column a, say.

Let's assume the term I am looking for is "This term".

What would a single complete example be with the basic syntax required to search for this phrase as above in b and return the respective a in MySQL as the Internet is totally unclear on this?

开发者_如何转开发

Basically, what would the mysql_query string look like for a text search?


$result = mysql_query("SELECT a FROM sometable WHERE b LIKE '%This term%'");

Depending on what you plan to do, MySQL Fulltext Indices might be interesting for you.


The following will look for 'This term' anywhere in b

SELECT a FROM table1 WHERE b LIKE('%This term%')

You could also just find records that start with 'This term'

SELECT a FROM table1 WHERE b LIKE('This term%')

The % operator is the wildcard in the like condition.


SELECT * FROM table1 
WHERE b LIKE '%This term%'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号