Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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, SvW May 8 '12 at 20:19

Questions on Server Fault are expected to relate to professional 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.

add comment

1 Answer 1

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
add comment

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