Introducing queries

Introduction to SQL

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

What is SQL useful for?

the library relational database

Introduction to SQL

Best for large datasets

Three database users asking different business questions to a database

Introduction to SQL

Keywords

Keywords are reserved words for operations

SELECT name

SELECT the name field

Common keywords: SELECT, FROM sql FROM patrons{ FROM the patrons table

Introduction to SQL

Our first query

SELECT name
FROM patrons;
| name   |
|--------|
| Izzy   |
| Maham  |
| Jasmin |
| James  |
  • Query results often called result set

 

 

the patrons table

Introduction to SQL

Selecting multiple fields

SELECT card_num, name
FROM patrons;
| card_num | name   |
|----------|--------|
| 54378    | Izzy   |
| 94722    | Maham  |
| 45783    | Jasmin |
| 90123    | James  |
SELECT name, card_num
FROM patrons;
| name   | card_num |
|--------|----------|
| Izzy   | 54378    |
| Maham  | 94722    |
| Jasmin | 45783    |
| James  | 90123    |
Introduction to SQL

Selecting multiple fields

SELECT name, card_num, total_fine
FROM patrons;
| card_num | name   | total_fine |
|----------|--------|------------|
| 54378    | Izzy   | 9.86       |
| 94722    | Maham  | 0          |
| 45783    | Jasmin | 2.05       |
| 90123    | James  | 0          |
Introduction to SQL

Selecting all fields

SELECT *
FROM patrons;
| card_num | name   | member_year | total_fine |
|----------|--------|-------------|------------|
| 54378    | Izzy   | 2012        | 9.86       |
| 94722    | Maham  | 2020        | 0          |
| 45783    | Jasmin | 2022        | 2.05       |
| 90123    | James  | 1989        | 0          |
Introduction to SQL

Let's practice!

Introduction to SQL

Preparing Video For Download...