Skip to content

Commit 7b20c69

Browse files
authored
Merge pull request #136 from jfrisina/gh-pages
Update 04-ordering-commenting.md
2 parents c6707db + 8cc2b4d commit 7b20c69

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

episodes/04-ordering-commenting.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Clauses are written in a fixed order: `SELECT`, `FROM`, `WHERE`, then `ORDER BY`
4040

4141
## Complex queries & commenting
4242

43+
The goal is to make a query easy to read and understand, even when the logic becomes complex. This can be handled in two ways:
44+
45+
1. Rewriting the query so that the logic is easy to follow
46+
2. Adding comments for context and clarity.
47+
4348
Consider the following query:
4449

4550
~~~
@@ -61,7 +66,7 @@ WHERE (ISSNs IN ('2076-0787', '2077-1444', '2067-2764|2247-6202'));
6166
We started with something simple, then added more clauses one by one, testing
6267
their effects as we went along. For complex queries, this is a good strategy, to make sure you are getting what you want. Sometimes it might help to take a subset of the data that you can easily see in a temporary database to practice your queries on before working on a larger or more complicated database.
6368

64-
When the queries become more complex, it can be useful to add comments to express, to yourself, or to others, what you are doing with your query. It's essentially a way of making notes within your SQL. In SQL, comments begin using <code class="language-plaintext highlighter-rouge">--</code> and end at the end of the line. To mark a whole paragraph as a comment, you can enclose it with the characters /* and */. For example, a commented version of the above query can be written as:
69+
When the queries become more complex, it can be useful to add comments to express to yourself, or to others, what you are doing with your query. Comments help explain the logic of a section and provide context for anyone reading the query. It's essentially a way of making notes within your SQL. In SQL, comments begin using <code class="language-plaintext highlighter-rouge">--</code> and end at the end of the line. To mark a whole paragraph as a comment, you can enclose it with the characters /* and */. For example, a commented version of the above query can be written as:
6570

6671
~~~
6772
/*In this section we want to give an example how to

0 commit comments

Comments
 (0)