Vitaliy Isikov
Vitaliy Isikov

Reputation: 3654

SELECT all value from table only once if they're duplicated

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 once if 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 |
|        C |
+----------+

I'm using mySQL and PHP, in case anyone asks.

Thanks.

Upvotes: 9

Views: 32655

Answers (2)

amosrivera
amosrivera

Reputation: 26514

SELECT adspot FROM table GROUP BY adspot

see: http://www.tizag.com/mysqlTutorial/mysqlgroupby.php

Upvotes: 8

Dre
Dre

Reputation: 4329

SELECT DISTINCT adspot FROM your_table; ( this may not perform well at all in large tables )

Upvotes: 23

Related Questions