mysql gt =_amp;lt;=amp;gt; operator in MySQL_MySQL
Opera
Have you ever seen "<=>" in a SQL query while using MySQL? Does it mean less and equals to and greater than? Actually if you consider it as the union of <= and =>, great, you are close to it. This is one form of equal operator in MySQL, it has the similar meaning to the = operator with some subtle difference.
According toMySQL documentation, <=> isNULL-safe equal. This operator performs an equality comparison like the=operator, but returnsrather thanNULLif both operands areNULL, andrather thanNULLif one operand isNULL.
For example:mysql> SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;-> 1, 1, 0mysql> SELECT 1 = 1, NULL = NULL, 1 = NULL;-> 1, NULL, NULL
Next let's get to know more details about <=> operator in MySQL. To be noted this operator is not standard SQL operator, it's only available in MySQL.
Similarity with=operator
Like the regular=operator, two values are compared and the result is either(not equal) or(equal); in other words:'a' <=> 'b'yieldsand'a' <=> 'a'yields.
Difference with=operator
Unlike the regular=operator, values ofNULLdon't have a special meaning and so it never yieldsNULLas a possible outcome; so:'a' <=> NULLyieldsandNULL <=> NULLyields.
Contrary to=, whereby'a' = NULLyieldsNULLand evenNULL = NULLyieldsNULL; BTW, almost all operators and functions in MySQL work in this manner, because comparing againstNULLis basically undefined.
Usefulness
This is very useful for when both operands may containNULLand you need a consistent comparison result between two columns.
Another use-case is with prepared statements, for example:...WHERE col_a <=>?...
Here, the placeholder can be either a scalar value orNULLwithout having to change anything about the query.
Related operators
Besides<=>there are also two other operators that can be used to compare againstNULL, namelyIS NULLandIS NOT NULL; they're part of the ANSI standard and therefore supported on other databases, unlike<=>, which is MySQL-specific.
You can think of them as specializations of MySQL's<=>:'a'ISNULL==>'a'<=>NULL'a'ISNOTNULL==>NOT('a'<=>NULL)
Based on this, your particular query (fragment) can be converted to the more portable:WHERE p.name ISNULL
相关标签:
本文原创发布php中文网,转载请注明出处,感谢您的尊重!
mysql gt =_amp;lt;=amp;gt; operator in MySQL_MySQL相关推荐
- mysql字典存储_python将字典内容存入mysql_MySQL
python 1.背景 项目需要,用python实现了将字典内容存入本地的mysql数据库.比如说有个字典dic={"a":"b","c": ...
- 用于React,React Native,JavaScript和生产力的顶级VSCode扩展
I've used VSCode full-time since 2016. Before I was using Visual Studio and I was looking for lighte ...
- MySQL数据库基础(三)数据的导入导出、管理表记录、匹配条件
数据的导入导出 搜索路径 查看搜索路径 安装时已经自动创建 命令:mysql > show variables like "secure_file_priv"; mysql& ...
- MySQL 隐式转换 字符串和整型说明
MySQL 隐式转换 字段类型定义 CREATE TABLE `user` (`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '编号',/* ...... * ...
- LeetCode MySQL 1440. 计算布尔表达式的值(case when then else end)
文章目录 1. 题目 2. 解题 1. 题目 表 Variables: +---------------+---------+ | Column Name | Type | +------------ ...
- freebsd 手工安装zabbix2.0 php,zabbix 服务端,子客户端安装配置日志
针对已经有mysql nginx php 的linux环境 ,zabbix2.4.8对不同版本的mysql会报不同的错,php也一样. 这只是针对本人的环境下的安装部署,mysql是5.6.4rmp安 ...
- 【OAI】部署5GSA独立组网网络切片例程及例程解析
文章目录 摘要 引言 关键技术介绍 5G核心网 核心网网元功能 网络切片 OAI Docker 官方例程详解 整体介绍 具体详解 网络切片架构 部署概览与说明 1-4 1.预先准备 5.部署OAI 5 ...
- 改造Benchmark SQL适配OceanBase开源版数据库跑TPC-C查看执行计划
改造Benchmark SQL5及SQL表性能调优适配OceanBase开源版数据库跑TPC-C测试 作者:马顺华 从事运维管理工作多年,目前就职于六棱镜(杭州)科技有限公司,熟悉运维自动化.Ocea ...
- 对mysql的总结与反思_一次DB故障引起的反思和MySQL Operator选型
前言 在一次数据库故障后,我们发现业务库会根据业务的等级会划分多个 MySQL 实例,许多业务库会同时属于一个 MySQL 实例,当一个库引发问题后整个实例的状态是不可控的.从而导致这个实例上的所有业 ...
最新文章
- SQL与NoSQL区别-扩展方式
- FPGA之道(53)状态机的模型
- 郑州网络推广教你如何“悄悄”做网站SEO,惊艳竞争对手?
- ASP.NET中AJAX的UpdatePannel控件的用法
- xss防御方法base64_XSS 防御方法总结
- 花神的数论题(这题...哎。数位dp咋就这么 not naive 呢)
- Linux :IO多路复用模型
- java基本数据类型转为String类型的4种常见方法
- php unserialize 实例,PHP ArrayIterator unserialize()用法及代码示例
- java 数组合并_数组与链表
- One River CEO:从长远来看比特币可能达到每枚50万美元
- 如何实现现实人脸照片的编码
- 【重识云原生】第六章容器6.1.3节——Docker常用命令
- linux海报制作软件,用 OpenOffice.org 3.2 Draw 制作海报
- 【知乎答案】2018校招,笔试应该怎么准备?|牛客网回答
- 支付宝是怎么炼成的?蚂蚁金融级研发效能实践解析
- Emacs footnote 自动排序
- 所希望于劳工会的〔1〕
- 「WinddowInsets(二)」我们能用WindowInsets做什么?
- JavaScript中的对象,如何创建对象,创建对象的7种模式