[英]Wrong pattern when using regexp w/ mysql ..?
I have a mysql table that's pretty simple & small. 我有一个非常简单和小的mysql表。
award_id bigint(11) primary key auto_inc
award_receip varchar(160) NULL
date_receip DATETIME NOT NULL
When I make the following query, I don't get the expected results. 当我进行以下查询时,我没有得到预期的结果。
SELECT * FROM awards WHERE award_id REGEXP '("1|6|3")'
Only award_id
6 is in the result set. 结果集中只有
award_id
6。 The primary keys are all consecutive into the thousands. 主键全部连续成千上万。
What's the error in my pattern that prevents award id
1 & award id
3 from being displayed in the results ? 我的模式中的错误是什么阻止
award id
1和award id
3显示在结果中?
Thanks !! 谢谢 !!
You shouldn't be using a regex at all. 你根本不应该使用正则表达式。
award_id
is BIGINT
, so use IN
: award_id
是BIGINT
,所以使用IN
:
SELECT * FROM awards WHERE award_id IN (1,6,3);
Just for completeness, if one were sadistic enough to use a regex, two of many possible patterns would be: 只是为了完整性,如果一个人足够悲伤使用正则表达式,许多可能的模式中的两个将是:
SELECT * FROM awards WHERE award_id RLIKE '^(1|6|3)$';
SELECT * FROM awards WHERE (award_id LIKE '1' OR award_id LIKE '6' OR award_id LIKE '3');
But yeah, don't use those, just use IN
. 但是,不要使用那些,只需使用
IN
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.