选择除MySQL中的一行以外的所有行 [英] Select all rows except one in MySQL

查看:74
本文介绍了选择除MySQL中的一行以外的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用select语句从某个MySQL表中获取所有行,但ID为4的表除外.

I'm trying to use a select statement to get all the rows from a certain MySQL table except for one which has in id of 4. Is there a simple way to do this?

推荐答案

您有一些选择:

SELECT * FROM table WHERE id != 4;

SELECT * FROM table WHERE NOT id = 4;

SELECT * FROM table WHERE id <> 4;

此外,考虑到将来某个时候,您可能希望将ID添加/删除到此列表中,也许另一个您不想选择的ID列表也将是一个好主意.

Also, considering perhaps sometime in the future you may want to add/remove id's to this list, perhaps another table listing id's which you don't want selectable would be a good idea.

在这种情况下,您将拥有:

In which case you would have:

SELECT * FROM table
WHERE id NOT IN (SELECT id FROM exempt_items_table);

这篇关于选择除MySQL中的一行以外的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆