用于"="的MySQL通配符-有一个 [英] MySQL Wildcard for "=" - is there one

查看:82
本文介绍了用于"="的MySQL通配符-有一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以

SELECT * FROM table WHERE col LIKE '%'

将返回所有内容.查询是否有通配符

will return everything. Is there a wildcard for the query

SELECT * FROM table WHERE col = '*'

很显然,*不起作用,我只是将其放在此处以指示我想要通配符的位置.我要从中选择的列包含1到12之间的整数,我希望能够选择具有特定编号的所有记录,或者具有通配符的所有记录.

Clearly * doesn't work, I just put it there to indicate where I'd like a wildcard. The column I'm selecting from contains an integer between 1 and 12, and I want to be able to select either all records with a particular number, or all records with a wildcard.

谢谢

推荐答案

LIKE与=基本上相同,只是LIKE允许您使用通配符.

LIKE is basically the same as =, except LIKE lets you use wildcards.

这两个查询将返回相同的结果:

These two queries will return the same results:

SELECT * FROM table WHERE col LIKE 'xyz';
SELECT * FROM table WHERE col='xyz';

在LIKE查询中没有'%',它实际上与'='相同.

Without a '%' in the LIKE query, it is effectively the same as '='.

如果要在整数列上进行选择,则应考虑使用IN()或BETWEEN运算符.听起来您有两个应该在代码中处理的单独条件,而不是在查询中处理,因为您的条件表明您至少需要两种不同的查询.

If you're doing a selection on an integer column, you should consider using the IN() or BETWEEN operators. It sounds like you have two separate conditions that should be handled in your code however, rather than in the query, as your conditions dictate that you need at least two different kinds of queries.

我应该澄清一下LIKE和=仅在普通的单调字符串比较用法中相似.您应该查看 MySQL手册的详细信息它是如何工作的,因为在某些情况下它是不一样的(例如语言集).

I should clarify that LIKE and = are similar only in normal, humdrum string comparison usage. You should check the MySQL Manual for specifics on how it works, as there are situations where it's not the same (such as language sets).

这篇关于用于"="的MySQL通配符-有一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆