MySQL 如果重复,则仅从表中选择所有值一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5240954/
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 value from table only once if they're duplicated
提问by Vitaliy Isikov
Lets say I have a table with the following rows/values:
假设我有一个包含以下行/值的表:
+--------+----------+
| ID | adspot |
+--------+----------+
| 1 | A |
| 2 | B |
| 3 | A |
| 4 | B |
| 5 | C |
| 6 | A |
+--------+----------+
I need a way to select the values in adspot but only onceif they're duplicated. So from this example I'd want to select A once and B once. The SQL result should look like this then:
我需要一种方法来选择 adspot 中的值,但如果它们重复,则只能选择一次。所以从这个例子中,我想选择一次 A 和一次 B。SQL 结果应如下所示:
+----------+
| adspot |
+----------+
| A |
| B |
| C |
+----------+
I'm using mySQL and PHP, in case anyone asks.
我正在使用 mySQL 和 PHP,以防万一。
Thanks.
谢谢。
回答by Dre
SELECT DISTINCT adspot FROM your_table;
( this may not perform well at all in large tables )
SELECT DISTINCT adspot FROM your_table;
(这在大表中可能根本表现不佳)
回答by amosrivera
SELECT adspot FROM table GROUP BY adspot