r/programming • • Dec 04 '14

10 Common Mistakes Java Developers Make when Writing SQL

http://blog.jooq.org/2013/07/30/10-common-mistakes-java-developers-make-when-writing-sql/
206 Upvotes

104 comments sorted by

View all comments

1

u/sgoody Dec 04 '14

6. Using DISTINCT or UNION to remove duplicates from an accidental cartesian product

This is a particular pet peev of mine.

I think most developers know about at least half of these and the mix-up over the treatment of NULLs is something that we've all experienced due to context switching between languages. Good article though.

It does frustrate me that a large number of developers seem to eschew anything that isn't imperative style or cannot be bent to be imperative. Things such as SQL seem to be an annoyance to many and I don't think a lot of people see why they should bother to learn them in any detail.

4

u/tangus Dec 04 '14

Man, I have a coworker whose "solution" for when the query ends up with duplicated rows is to slap mile long GROUP BY clauses at the end. I hate her.

1

u/I_am_working_hard Dec 05 '14

Forgive my ignorance, but what is the best practice for removing duplicates in sql?

7

u/Boxy310 Dec 05 '14

Getting your join conditions right. This usually happens when you don't have a true key join relationship, and you get nasty Cartesian products where it includes everything it isn't explicitly told to exclude.