Docsity

Introduction to SQL: A Beginner's Guide to Querying Data, Summaries of Computer science

Partial preview of the text

Download Introduction to SQL: A Beginner's Guide to Querying Data and more Summaries Computer science in PDF only on Docsity!

Introducing queries

I N T R O D U C T I O N T O S Q L

Izzy Weber

Curriculum Manager, DataCamp

What is SQL useful for?

Keywords Keywords are reserved words for operations SELECT name

Common keywords: SELECT , FROM

FROM patrons

Our first query SELECT name FROM patrons;

name
Izzy
Maham
Jasmin
James

Query results often called result set

Selecting multiple fields SELECT name, card_num, total_fine FROM patrons;

card_numnametotal_fine
54378Izzy9.86
94722Maham0
45783Jasmin2.05
90123James0

Selecting all fields SELECT * FROM patrons;

card_numnamemember_yeartotal_fine
54378Izzy20129.86
94722Maham20200
45783Jasmin20222.05
90123James19890

Writing queries

I N T R O D U C T I O N T O S Q L

Izzy Weber

Curriculum Manager, DataCamp

Aliasing Use aliasing to rename columns SELECT name AS first_name, year_hired FROM employees;

first_nameyear_hired
Darius2020
Raven2017
Eduardo2022
Maggie2021
Amy2020
Meehir2021

DISTINCT with multiple fields SELECT dept_id, year_hired FROM employees;

dept_idyear_hired
12020
22017
22022
32021
22020
32021

DISTINCT with multiple fields SELECT DISTINCT dept_id, year_hired FROM employees;

dept_idyear_hired
12020
22017
22022
32021
22020

Using views SELECT id, name FROM employee_hire_years;

idname
54378Darius
94722Raven
45783Eduardo
90123Maggie
67284Amy
26148Meehir

Let's practice!

SQL flavors

Both free and paid

All used with relational databases

Vast majority of keywords are the same

All must follow universal standards

Only the additions on top of these

standards make flavors different

Table flatlay photo created by freepik www.freepik.com 1

Two popular SQL flavors PostgreSQL

Free and open-source relational database system

Created at the University of California, Berkeley

"PostgreSQL" refers to both the PostgreSQL database system and its associated SQL flavor

SQL Server

Has free and paid versions

Created by Microsoft

T-SQL is Microsoft's SQL flavor, used with SQL Server databases