PDA

View Full Version : Selecting unique values from a table (NOT DISTINCT!)


fractalbit
07-29-2007, 12:36 AM
Hello all, i currently have a problem that although seems simple i cannot solve it.

Lets say we have a table that has the field photo_id and has values of it many times. For example 245 can exist any number of times (1, 5, 8, e.t.c.).

I want to select the values that exist in the table ONLY ONCE. Please note that i dont want to select each value once (using DISTINCT), that would return all the values that exist in the table.

For example lets say the table has the following values:

245
563
776
224
563
563
776
776
776
776

The query i want to make should return only the values 245 and 224 as 563 and 776 exist many times in that table.

Any help would be greatly appreciated.

guelphdad
07-29-2007, 05:57 AM
SELECT
yourfield
FROM
yourtable
GROUP BY
yourfield
HAVING count(yourfield) =1