The Select Statement is used to extract or query data from a database and can be broken down into the following core parts:
Eg. The select statement to return all the Customers in the QuickEasy database, starting with 'A' and sorted by company name, could look like this:
Spaces and line breaks are ignored, so leaving blank lines between the different parts of your select statement can make your SQL much more readable.
Another way to make your SQL more readable is the use of UPPER and lower case. In this tutorial, we will be using UPPERCASE for all the field and table names and lowercase for the rest of the statement.
Comments can be used to explain how you queries work and to highlight where variables might need to be changed. This is especially useful when porting queries across different databases and when other persons need to support your clients. There are two types of comments that can be used:
Line comments -- comment
-- Comments the rest of the line
Block comments /* comment */
/* Block comments can stretch over multiple lines. They are ideal for creating a detailed description of how a query works. They are also useful for commenting out blocks of a query that might be returning errors*/