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相关推荐

  1. mysql字典存储_python将字典内容存入mysql_MySQL

    python 1.背景 项目需要,用python实现了将字典内容存入本地的mysql数据库.比如说有个字典dic={"a":"b","c": ...

  2. 用于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 ...

  3. MySQL数据库基础(三)数据的导入导出、管理表记录、匹配条件

    数据的导入导出 搜索路径 查看搜索路径 安装时已经自动创建 命令:mysql > show variables like "secure_file_priv"; mysql& ...

  4. MySQL 隐式转换 字符串和整型说明

    MySQL 隐式转换 字段类型定义 CREATE TABLE `user` (`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '编号',/* ...... * ...

  5. LeetCode MySQL 1440. 计算布尔表达式的值(case when then else end)

    文章目录 1. 题目 2. 解题 1. 题目 表 Variables: +---------------+---------+ | Column Name | Type | +------------ ...

  6. freebsd 手工安装zabbix2.0 php,zabbix 服务端,子客户端安装配置日志

    针对已经有mysql nginx php 的linux环境 ,zabbix2.4.8对不同版本的mysql会报不同的错,php也一样. 这只是针对本人的环境下的安装部署,mysql是5.6.4rmp安 ...

  7. 【OAI】部署5GSA独立组网网络切片例程及例程解析

    文章目录 摘要 引言 关键技术介绍 5G核心网 核心网网元功能 网络切片 OAI Docker 官方例程详解 整体介绍 具体详解 网络切片架构 部署概览与说明 1-4 1.预先准备 5.部署OAI 5 ...

  8. 改造Benchmark SQL适配OceanBase开源版数据库跑TPC-C查看执行计划

    改造Benchmark SQL5及SQL表性能调优适配OceanBase开源版数据库跑TPC-C测试 作者:马顺华 从事运维管理工作多年,目前就职于六棱镜(杭州)科技有限公司,熟悉运维自动化.Ocea ...

  9. 对mysql的总结与反思_一次DB故障引起的反思和MySQL Operator选型

    前言 在一次数据库故障后,我们发现业务库会根据业务的等级会划分多个 MySQL 实例,许多业务库会同时属于一个 MySQL 实例,当一个库引发问题后整个实例的状态是不可控的.从而导致这个实例上的所有业 ...

最新文章

  1. SQL与NoSQL区别-扩展方式
  2. FPGA之道(53)状态机的模型
  3. 郑州网络推广教你如何“悄悄”做网站SEO,惊艳竞争对手?
  4. ASP.NET中AJAX的UpdatePannel控件的用法
  5. xss防御方法base64_XSS 防御方法总结
  6. 花神的数论题(这题...哎。数位dp咋就这么 not naive 呢)
  7. Linux :IO多路复用模型
  8. java基本数据类型转为String类型的4种常见方法
  9. php unserialize 实例,PHP ArrayIterator unserialize()用法及代码示例
  10. java 数组合并_数组与链表
  11. One River CEO:从长远来看比特币可能达到每枚50万美元
  12. 如何实现现实人脸照片的编码
  13. 【重识云原生】第六章容器6.1.3节——Docker常用命令
  14. linux海报制作软件,用 OpenOffice.org 3.2 Draw 制作海报
  15. 【知乎答案】2018校招,笔试应该怎么准备?|牛客网回答
  16. 支付宝是怎么炼成的?蚂蚁金融级研发效能实践解析
  17. Emacs footnote 自动排序
  18. 所希望于劳工会的〔1〕
  19. 「WinddowInsets(二)」我们能用WindowInsets做什么?
  20. JavaScript中的对象,如何创建对象,创建对象的7种模式

热门文章

  1. 电脑如何批量下载哔哔视屏_我是电脑哔哔哔哔哔
  2. Android小Demo——绘制小机器人
  3. win10系统桌面图标变为白色方框和去除桌面图标快捷方式小箭头的方法
  4. iOS-Core Animation 核心动画高级编程/3-图层几何学
  5. python树莓派串口通信实例_使用树莓派和Python实现ModbusTCP通讯
  6. 产品读书《六顶思考帽》
  7. 重走来时路,这一次我会披荆斩棘
  8. Spring cloud实现FeignClient指定Zone调用
  9. 现代C++之手写智能指针
  10. 浅谈支付宝第三方支付