mysql except
时间: 2023-10-12 22:19:14 浏览: 26
`EXCEPT` is not a valid keyword in MySQL. In MySQL, you can use `NOT IN` or `LEFT JOIN` to achieve the same functionality as `EXCEPT`.
For example, to select all the rows from table1 that are not present in table2, you can use the following query:
```
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
```
Alternatively, you can use a `LEFT JOIN` to achieve the same result:
```
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id = table2.id WHERE table2.id IS NULL;
```
相关问题
mysql except用不了
MySQL 中没有 `EXCEPT` 关键字,但是可以使用 `NOT IN` 或 `LEFT JOIN` 来实现类似的功能。以下是使用 `NOT IN` 实现 `EXCEPT` 的示例:
假设有两个表 A 和 B,需要从 A 中排除 B 中存在的数据,可以使用以下 SQL 语句:
```
SELECT * FROM A WHERE A.id NOT IN (SELECT id FROM B);
```
这将返回 A 表中存在但是 B 表中不存在的数据。
另外,使用 `LEFT JOIN` 也可以实现类似的功能,具体可以参考以下 SQL 语句:
```
SELECT A.* FROM A LEFT JOIN B ON A.id = B.id WHERE B.id IS NULL;
```
这将返回 A 表中存在但是 B 表中不存在的数据。
mysql except关键字用不了
MySQL中没有`EXCEPT`关键字,但可以使用`NOT IN`或`LEFT JOIN`和`NULL`来实现类似的功能。例如,以下查询将返回`table1`中有但`table2`中没有的行:
```
SELECT column1, column2, ...
FROM table1
WHERE column1 NOT IN (SELECT column1 FROM table2);
```
或者使用`LEFT JOIN`和`NULL`:
```
SELECT table1.column1, table1.column2, ...
FROM table1
LEFT JOIN table2 ON table1.column1 = table2.column1
WHERE table2.column1 IS NULL;
```