Query execution

Intermediate SQL

Jasmin Ludolf

Data Science Content Developer, DataCamp

Order of execution

  • SQL is not processed in its written order
-- Order of execution

SELECT name
FROM people
LIMIT 10;
  • LIMIT limits how many results we return
  • Good to know processing order for debugging and aliasing
  • Aliases are declared in the SELECT statement
Intermediate SQL

Debugging SQL

SELECT nme
FROM people;
field "nme" does not exist
LINE 1: SELECT nme
               ^
HINT:  Perhaps you meant to reference the field "people.name".
  • Misspelling
  • Incorrect capitalization
  • Incorrect or missing punctuation
Intermediate SQL

Comma errors

  • Look out for comma errors!
SELECT title, country duration
FROM films;
syntax error at or near "duration"
LINE 1: SELECT title, country duration
                      ^
Intermediate SQL

Keyword errors

SELCT title, country, duration
FROM films;
syntax error at or near "SELCT"
LINE 1: SELCT title, country, duration
        ^
Intermediate SQL

Final note on errors

Most common errors:

  • Misspelling
  • Incorrect capitalization
  • Incorrect or missing punctuation, especially commas

 

Learn by making mistakes

Digital image of a laptop and magnifying glass highlighting a bug in the code

Intermediate SQL

Let's practice!

Intermediate SQL

Preparing Video For Download...