Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

share|improve this question

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:

select distinct id from tablename where id="10"

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:

select distinct * from tablename where id="10"

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.