Search code examples
sqldistinct-valuespolyhedra

DISTINCT clause used on non-distinct select error


I want to populate a drop down box using the one field from by data, I just want the unique values returned for a set of data from one table. Group by is not implemented in the polyhedra database I am using. Name is primary key for table and all names are unique.

I am trying to run this query:

SELECT DISTINCT userstring05
FROM digital
WHERE userstring05 LIKE '_%'
  AND name LIKE '200-B%'

But I get this error:

DISTINCT clause used on non-distinct select


Solution

  • From ENEA Polyhedra reference:

    Inclusion of the distinct clause will generate an error if the select statement could potentially return duplicate rows. Only select statements whose output columns include all the primary key columns of the tables specified in the from clause can be successfully executed with a distinct clause.

    So I guess this DBMS doesn't really implement distinct, as this constraint nullifies the interest of using this clause. Unless you join a table without any primary key, maybe ?

    EDIT: Seems like this resource is old. Which version of Polyhedra are you using ?