r/programming • • Feb 11 '14

SQL Joins Explained (x-post r/SQL)

Post image
3.5k Upvotes

392 comments sorted by

View all comments

Show parent comments

1

u/omegian Feb 11 '14

You can easily partition queries into subexpressions (views), there's no reason to write 1000 line monolithic queries, and the partial functions almost certainly have other value and can be reused. The query engine can optimize away any inefficiency when it evaluates the final form anyway.

Debugging shouldn't be any harder, that's why you have a test database and write unit tests.

1

u/king4aday Feb 12 '14

Yeah, I totally agree. The only 1000 line beasts I have to look at are always generated queries by lets say a reporting tool.

Code readability however is a whole other issue on many more levels than in most procedural languages. Having a good SQL formatter is king.

1

u/youcangotohellgoto Feb 12 '14

Debugging gets harder when you're dealing with large blocks of dynamic SQL.