Home > Database > SQL > What does minus mean in sql

What does minus mean in sql

下次还敢
Release: 2024-05-02 01:24:15
Original
1096 people have browsed it

MINUS operator is used in SQL to return rows that exist in the first table but not in the second table. Its syntax is: SELECT FROM table1 MINUS SELECT FROM table2. It is similar to the EXCEPT operator, but only returns rows that exist in the first table but not in the second table.

What does minus mean in sql

MINUS in SQL

MINUS operator is a set operator in SQL, used to select Returns rows from two tables that exist in the first table but not in the second table.

Syntax

<code>SELECT * FROM table1 MINUS SELECT * FROM table2;</code>
Copy after login

Function

The MINUS operator will select all items not # from table1 rows in ##table2. The resulting table contains only rows that are unique in table1.

Example

Suppose we have two tables:

Employees and Resigned Employees. We need to find employees who are still employed:

<code>SELECT * FROM 员工 MINUS SELECT * FROM 离职员工;</code>
Copy after login
The result table will only contain records of employees who are still employed.

Differences from EXCEPT

The MINUS operator is similar to the EXCEPT operator, but slightly different:

  • MINUS Return only rows that exist in the first table but not in the second table.
  • EXCEPT Also returns rows that exist in the first table but not in the second table, and rows that exist in the second table but do not exist in the first table. rows that exist.

Note

    The MINUS operator can only be used when two tables have the same columns and data types.
  • The column order in the result table is the same as the column order in
  • table1.
  • NULL values ​​are treated as null, so they do not affect the result of the MINUS operator.

The above is the detailed content of What does minus mean in sql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template