Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Comparison Functions and Operators

Updated on 2024-12-13 GMT+08:00

Comparison

Operation

Description

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

=

Equal to

<>

Not equal to

!=

Not equal to

  • Scope comparison: between

    between is applicable to values in a specified range, for example, value BETWEEN min AND max.

    Not between is used when the value is not in a specified range.

    The null value cannot be used in the between operation. The execution results of the following two operations are Null:

    SELECT NULL BETWEEN 2 AND 4; -- null
    SELECT 2 BETWEEN NULL AND 6; -- null

    In HetuEngine, the value, min, and max parameters must be of the same data type in BETWEEN and NOT BETWEEN.

    Wrong usage: 'John' between 2.3 and 35.2

    Example expression equivalent to BETWEEN:

    SELECT 3 BETWEEN 2 AND 6; -- true
    SELECT 3 >= 2 AND 3 <= 6; -- true

    Example expression equivalent to NOT BETWEEN:

    SELECT 3 NOT BETWEEN 2 AND 6; -- false
    SELECT 3 < 2 OR 3 > 6; -- false
  • IS NULL and IS NOT NULL

    They are used to determine whether a value is empty. All data types can be used for this determination.

    SELECT 3.0 IS NULL; -- false
  • IS DISTINCT FROM and IS NOT DISTINCT FROM

    This is a special usage. In HetuEngine SQL statements, NULL indicates an unknown value. All comparisons related to NULL also produce NULL results. IS DISTINCT FROM and IS NOT DISTINCT FROM can take a null value as a known value and return true or false (even if the expression contains a null value).

    Example:

    --Create a table.
    create table dis_tab(col int);
    --Insert data.
    insert into dis_tab values (2),(3),(5),(null);
    --Query:
    select col from dis_tab where col is distinct from null;
     col
    ----
     2 
     3 
     5
    (3 rows)

    The following truth table demonstrates how IS DISTINCT FROM and IS NOT DISTINCT FROM process common data and NULL values.

    a

    b

    a = b

    a <> b

    a DISTINCT b

    a NOT DISTINCT b

    1

    1

    TRUE

    FALSE

    FALSE

    TRUE

    1

    2

    FALSE

    TRUE

    TRUE

    FALSE

    1

    NULL

    NULL

    NULL

    TRUE

    FALSE

    NULL

    NULL

    NULL

    NULL

    FALSE

    TRUE

  • GREATEST and LEAST

    The two functions are not standard SQL functions. They are typical extensions. The parameter cannot contain null values.

    • greatest(value1, value2, ..., valueN)

      Returns the provided maximum value.

    • least(value1, value2, ..., valueN) → [same as input]

      Returns the provided minimum value.

  • Batch comparison: ALL, ANY, and SOME

    Quantifiers ALL, ANY, and SOME can be used together with comparison operators in the following ways:

    expression operator quantifier ( subquery )

    The meanings of some combinations of quantifiers and comparison operators are as follows. ANY and SOME have the same meaning. You can replace ANY with SOME when using the expressions in the following table.

    Expression

    Definition

    A = ALL (...)

    Returns true when A is equal to all values.

    A <> ALL (...)

    Returns true when A is not equal to any value.

    A < ALL (...)

    Returns true when A is less than the minimum value.

    A = ANY (...)

    Returns true when A is the same as any value, which is equivalent to A IN (...).

    A <> ANY (...)

    Returns true when A is different from any value.

    A < ANY (...)

    Returns true when A is less than the maximum value.

    Example:

    SELECT 'hello' = ANY (VALUES 'hello', 'world'); -- true
    SELECT 21 < ALL (VALUES 19, 20, 21); -- false
    SELECT 42 >= SOME (SELECT 41 UNION ALL SELECT 42 UNION ALL SELECT 43);-- true

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback