• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

MySQL Command: NOT

December 19, 2023

MySQL Command: NOT

In MySQL, the NOT command is a logical operator that negates a condition. It is used to reverse the result of a Boolean expression, making it a valuable tool for filtering and manipulating data in a database. This article will explore the various applications of the NOT command in MySQL and provide examples to illustrate its usage.

Basic Syntax

The basic syntax of the NOT command in MySQL is as follows:

SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;

The NOT command is typically used in conjunction with the WHERE clause to filter rows based on a specified condition. It negates the condition, returning all rows that do not satisfy the given criteria.

Example: Filtering Data

Let’s consider a scenario where we have a table named “customers” with the following columns: “id”, “name”, and “age”. We want to retrieve all customers who are not teenagers (i.e., not between the ages of 13 and 19).

SELECT *
FROM customers
WHERE NOT age BETWEEN 13 AND 19;

This query will return all rows from the “customers” table where the “age” column is not between 13 and 19. It effectively filters out the teenagers, giving us a list of customers who are either younger or older than the specified age range.

Example: Negating Conditions

The NOT command can also be used to negate other conditions, such as equality or inequality. Let’s say we have a table named “products” with columns “id”, “name”, and “price”. We want to retrieve all products that are not priced at $10.

SELECT *
FROM products
WHERE NOT price = 10;

This query will return all rows from the “products” table where the “price” column is not equal to 10. It excludes the products with a price of $10, giving us a list of products with different price points.

Example: Combining Conditions

The NOT command can also be combined with other logical operators, such as AND and OR, to create more complex conditions. Let’s consider a table named “orders” with columns “id”, “customer_id”, and “status”. We want to retrieve all orders that are not canceled and not delivered.

SELECT *
FROM orders
WHERE NOT (status = 'canceled' OR status = 'delivered');

This query will return all rows from the “orders” table where the “status” column is neither “canceled” nor “delivered”. It excludes the orders with these statuses, giving us a list of orders that are still in progress or have a different status.

Summary

The NOT command in MySQL is a powerful tool for negating conditions and filtering data. It allows you to reverse the result of a Boolean expression, providing flexibility in querying and manipulating your database. By using the NOT command in conjunction with the WHERE clause, you can easily exclude rows that do not meet specific criteria. Understanding how to use the NOT command effectively can greatly enhance your ability to retrieve and analyze data in MySQL.

For more information about VPS hosting services, visit Server.HK.

Recent Posts

  • VPS Hosting vs Shared Hosting: Why the Upgrade Is Worth It for Asia-Facing Websites
  • Hong Kong VPS vs Google Cloud Asia: Which Delivers Better China Performance in 2026?
  • Why No-ICP-Filing Hong Kong Hosting Is the Smart Choice for Cross-Border E-Commerce
  • Hong Kong VPS vs AWS Hong Kong Region: Cost, Latency, and Control Compared
  • Data Privacy Laws in Hong Kong: What VPS Users Need to Know

Recent Comments

  1. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  2. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026
  3. levitra price on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  4. finasterid on Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  5. doxycycline hyclate 100mg on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot