Tips for Building Complex Queries

The following are tips that may help you out when you come across problems requiring complex queries:

  • If a request for a query comes to you in the form of hard copy, discreetly place it on your coworker's desk. (Just kidding!)

  • Understand what the requester is asking for.

  • Identify the tables that should be used to resolve the query.

  • Study the relationships between your tables. Know what data to expect from queries.

  • Describe the tables to determine what the exact column names are. You should show only pertinent information on the report.

  • Sometimes it is helpful to construct a rough draft of the query on paper before you attempt to type it into a file and run it.

  • Code one piece at a time. If the report is complicated, ...

Get Sams Teach Yourself SQL in 21 Days, Fourth 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.