DEV Community

Discussion on: How to write SQL queries which are easier to read?

Collapse
 
schmowser profile image
Victor Warno

Hey javinpaul, thanks for encouraging proper capitalization in order to have readable queries. When I read very long and complex queries, I often get lost as well. Do you also have techniques how to cope with multiple UNIONs and a WITH sections in one query? Is one big query better or worse than multiple small but comprehensive ones?

Sometimes I had struggles reading parts of your article. Could it be that your images are jumbled up? The first query (1.0) is not written all in one line as the description states. The first image of 3.0 is not indented. Also, in the second one of 3.0, shouldn't it be 1=1 instead of 1==1? There you could actually mention this as a cool trick, to have the possibility to comment conditions out (without commenting the WHERE keyword)!

Also, there is a typo:
tecach -> teach

Thank you for the links as well! Haven't heard of T-SQL yet.

Collapse
 
javinpaul profile image
javinpaul

Hello @victor , first of all very valuable comment.

  1. I have corrected the typo, thanks for that.
  2. In the first version, it was indeed in one line but I had to break just to show that properly in this article.
  3. Yes, somehow indention lost in the image on 3rd, the capital version has a proper indentation.
  4. Yes, using WHERE 1=1 is a nice trick I learned to easily comment condition and try query.
  5. Regarding multiple UNION, could you elaborate more? I think this style will help but I generally use brackets ()
  6. For with queries also, I prefer brackets.

Once again thanks for the comment and making the article better.