Sql查询可以添加更多约束 [英] Sql query can we add more constraints

查看:90
本文介绍了Sql查询可以添加更多约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个表有这些列::



列ID ::列名:::列desc :::列a ::列b



如果查询是从表中选择*,其中columnid像'0';



其返回数据与columnid 0 only



我们可以这样做:: select * from table其中columnid如'0','1','2'; ?

if a table have these columns ::

Column ID:: Column Name ::: Column desc ::: column a :: Column b

and if the query is select * from table where columnid like '0';

its return data related to columnid 0 only

and can we do this :: select * from table where columnid like '0','1','2'; ?

推荐答案

ColumnID IN ('0','1','2') 






如果你只是寻找bitid值为0的记录,那么这是更好的:

Hi,

If you're only looking for the record that has the columnid value of 0, then this is better:
select * from table where columnid = '0';





你真的不能这样做:



You can't really do:

select * from table where columnid like '0','1','2';





如果您要检索columnid值为0 1的记录或2,然后这将工作:



If you are trying to retrieve records that have a columnid value of 0 1 or 2, then this would work:

select * from table where columnid IN ('0','1','2');



...如果将columnid定义为整数数据类型,那么你最好用:


... and if columnid is defined as an integer data type, then you would be better with:

select * from table where columnid IN (0,1,2);





希望有所帮助。



Hope it helps.


这篇关于Sql查询可以添加更多约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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