Chapter 3. The SQL Language

This chapter covers SQL fundamentals including its standards, key terms, and sublanguages, along with answers to the following questions:

Comparison to Other Languages

Some people in the technology space don’t consider SQL to be a real programming language.

While SQL stands for “Structured Query Language,” you can’t use it in the same way as some other popular programming languages like Python, Java, or C++. With those languages, you can write code to specify the exact steps that a computer should take to get a task done. This is called imperative programming.

In Python, if you want to sum up a list of values, you can tell the computer exactly how you want to do so. The following example code goes through a list, item by item, and adds each value to a running total, to finally calculate the total sum:

calories = [90, 240, 165]
total = 0
for c in calories:
    total += c
print(total)

With SQL, instead of telling a computer exactly how you want to do something, you just describe what you want done, which in this case is to calculate the sum. Behind the scenes, SQL figures out how to optimally execute the code. This is called declarative programming.

SELECT SUM(calories)
FROM workouts;

The main takeaway here is that SQL is not a general-purpose programming language like Python, ...

Get SQL Pocket Guide, 4th 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.