[英]search multiple string in a column.using php and mysql
in my mysql table.there is a column like this. 在我的mysql table.there有这样的一列。
column_name
apple
ball
cat
daddy
mom
I have two strings (cat and ball for example) So I need to get records that match cat and ball strings. 我有两个字符串(例如cat和ball),所以我需要获取与cat和ball字符串匹配的记录。 I can get one using
我可以用一个
SELECT * FROM table_name WHERE column_name='cat'
but how to get two records that match my two strings(I mean column_name='cat' and column_name='ball'
) please anyone help me 但是如何获取与我的两个字符串匹配的两个记录(我的意思是
column_name='cat' and column_name='ball'
),请有人帮我
You can use an IN
statement, which acts as an extended OR
: 您可以使用
IN
语句,它用作扩展的OR
:
SELECT *
FROM `table_name`
WHERE `column_name` IN ('cat', 'ball');
I guess you can use 'OR' 我猜你可以使用“或”
SELECT * FROM table_name WHERE column_name='cat' OR column_name='ball'
For reference http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_where_or 供参考http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_where_or
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.