On executing the following query I am getting multiple records as result with each having id=10. If I am using distinct keyword, then I should get just one record. What could be the cause?
"select distinct(id) from tablename where id="10"
closed as off topic by Ladadadada, EightBitTony, SmallClanger, Greg Askew, Sven♦ May 8 '12 at 20:19
Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.
You really should provide some test data, and let us know which SQL you are using (TSQL/MySQL/psql). By your tags, I assume your using psql.
Acording to the Postgres Docs you should do something like this:
This will just return one row/col that contains 10 if there is one in your table, if you want all the different varieties of rows where id="10" in your table without any duplicates, than you can do:
Your syntax appears to be calling distinct as a function, not an sql keyword look at this
Also, if "id" is really an id for your rows, perhaps you should consider making it a primary key. Then there will only be one row with that value allowed in the table.