Formatting Your SQL Statement

Formatting your SQL statement sounds like an obvious statement; as obvious as it may sound, it is worth mentioning. There are several things that a newcomer to SQL will probably not take into consideration when building an SQL statement. The following sections discuss the listed considerations; some are common sense, others are not so obvious:

  • Formatting SQL statements for readability

  • The order of tables in the FROM clause

  • The placement of the most restrictive conditions in the WHERE clause

  • The placement of join conditions in the WHERE clause

Note

Most relational database implementations have what is called an SQL optimizer, which evaluates an SQL statement and determines the best method for executing the statement ...

Get Sams Teach Yourself SQL in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.