选择 MySQL 中除一行之外的所有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6260449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select all rows except one in MySQL
提问by woninana
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 语句从某个 MySQL 表中获取所有行,但 id 为 4 的行除外。有没有一种简单的方法可以做到这一点?
回答by Tim
You have a few options:
您有几个选择:
SELECT * FROM table WHERE id != 4;
SELECT * FROM table WHERE NOT id = 4;
SELECT * FROM table WHERE id <> 4;
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.
此外,考虑到将来某个时候您可能希望在此列表中添加/删除 id,也许另一个列出您不希望选择的 id 的表是一个好主意。
In which case you would have:
在这种情况下,您将拥有:
SELECT * FROM table
WHERE id NOT IN (SELECT id FROM exempt_items_table);
回答by Christopher Armstrong
select * from table where some_id != 4
回答by Stuti
select * from <table name> where <column - name> != <value>;