# 12 Common Mistakes and Missed Optimization Opportunities in SQL

DevFeed: [12 Common Mistakes and Missed Optimization Opportunities in SQL](<https://devfeed.tech/articles/12-common-mistakes-and-missed-optimization-opportunities-in-sql-33936.md>)

Original publisher: [Read original article](<https://hakibenita.com/sql-dos-and-donts>)

Author: Haki Benita

Published: 2019-11-20T22:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [SQL](<https://devfeed.tech/topics/sql.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [databases](<https://devfeed.tech/tags/databases.md>), [developers](<https://devfeed.tech/tags/developers.md>), [mistakes](<https://devfeed.tech/tags/mistakes.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

## AI overview

A practical guide to common SQL mistakes and missed optimization opportunities. It explains issues including integer division, division by zero, NULL handling, UNION versus UNION ALL, and counting values in PostgreSQL.

## Source excerpt

SQL is used by analysts, data scientists, product managers, designers and many others. These professionals have access to databases, but they don't always have the intuition and understanding to write efficient queries. In an effort to make my team write better SQL, I went over reports written by non-developers and code reviews, and gathered common mistakes and missed optimization opportunities in SQL.