Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SQL Basics - RRUG 1/6/2016
Search
kickinbahk
January 06, 2016
Technology
0
130
SQL Basics - RRUG 1/6/2016
Overview of SQL and basic syntax.
kickinbahk
January 06, 2016
Tweet
Share
More Decks by kickinbahk
See All by kickinbahk
OptOutside App
kickinbahk
0
52
Ensuring The Happy Path - Mobile Dev + Test
kickinbahk
0
120
Optionals, Protocols and Extensions - Swift by Example - SoCal Code Camp '16
kickinbahk
0
75
Intro to Elm - RRuG 05/2016
kickinbahk
0
160
WebSockets Intro - Riverside Ruby Group - 03/2016
kickinbahk
0
79
ES2015 and Your Rails App - Riverside Ruby Group
kickinbahk
0
180
Demystifying the Wizardry of Regular Expressions - LV DotNet Meetup - 01/2016
kickinbahk
0
190
Demystifying the Wizardry of Regular Expressions - SoCal Code Camp '15 - LA
kickinbahk
0
220
Becoming a Polyglot Programmer through the Eyes of a Freelance Musician - SoCal Code Camp 15 - LA
kickinbahk
0
140
Other Decks in Technology
See All in Technology
JavaにおけるNull非許容性
skrb
1
260
エンジニアリング価値を黒字化する バリューベース戦略を用いた 技術戦略策定の道のり
kzkmaeda
6
1.5k
OpenID BizDay#17 KYC WG活動報告(法人) / 20250219-BizDay17-KYC-legalidentity
oidfj
0
450
EDRの検知の仕組みと検知回避について
chayakonanaika
8
4.2k
Classmethod AI Talks(CATs) #17 司会進行スライド(2025.02.19) / classmethod-ai-talks-aka-cats_moderator-slides_vol17_2025-02-19
shinyaa31
0
170
クラウドサービス事業者におけるOSS
tagomoris
3
970
ビジネスモデリング道場 目的と背景
masuda220
PRO
9
690
プロダクトエンジニア 360°フィードバックを実施した話
hacomono
PRO
0
130
EMConf JP 2025 懇親会LT / EMConf JP 2025 social gathering
sugamasao
2
160
1行のコードから社会課題の解決へ: EMの探究、事業・技術・組織を紡ぐ実践知 / EM Conf 2025
9ma3r
6
1.9k
人はなぜISUCONに夢中になるのか
kakehashi
PRO
6
1.7k
2025-02-21 ゆるSRE勉強会 Enhancing SRE Using AI
yoshiiryo1
1
450
Featured
See All Featured
Building an army of robots
kneath
303
45k
Raft: Consensus for Rubyists
vanstee
137
6.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
Optimizing for Happiness
mojombo
376
70k
The Language of Interfaces
destraynor
156
24k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
Designing for humans not robots
tammielis
250
25k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Docker and Python
trallard
44
3.3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Transcript
SQL BASICS
SQL - Structured Query Language
A Computer Language used for: •Storing, •Manipulating, •Querying
Data stored in relational databases
RELATIONAL DATABASES
A collection of data items organized as a set of
formally-described tables from which data can be accessed or reassembled in many different ways without having to reorganize the database tables.
None
Set of tables with data organized by predefined categories
Each row contains a unique instance of data for the
categories defined by the columns.
None
SQL FLAVORS
•Standard •PostgreSQL •DB2 •MicrosoftSQL •MySQL •Oracle •Informix
SQL is Standardized but different flavors are variations
Compare flavors: http://troels.arvin.dk/db/rdbms/ https://en.wikibooks.org/wiki/SQL_Dialects_Reference
SYNTAX
SELECT
Used to select data from the tables located in a
database.
Two keywords: we need to SELECT information FROM a table.
SELECT "column_name" FROM "table_name"; Syntax:
SELECT Store_Name FROM Store_Information; Syntax:
Store_Name Los Angeles San Diego Los Angeles Boston Result:
Select Multiple Columns
SELECT Store_Name, Sales FROM Store_Information; Syntax:
Store_Name Sales Los Angeles 1500 San Diego 250 Los Angeles
300 Boston 700 Result:
Select All Columns 2 ways…
SELECT Store_Name, Sales, Txn_Date FROM Store_Information; Syntax:
SELECT * FROM Store_Information; Syntax:
Select Distinct
SELECT - all information from a column (or columns) on
a table
This may cause redundancies.
To grab a distinct element, all we need to do
is to add DISTINCT after SELECT
SELECT DISTINCT Store_Name FROM Store_Information; Syntax:
Store_Name Los Angeles San Diego Boston Result:
Where
WHERE - allows filtering the result set based on certain
conditions.
SELECT "column_name" FROM "table_name" WHERE "condition";
SELECT Store_Name FROM Store_Information WHERE Sales > 1000; Syntax:
Store_Name Los Angeles Result:
Where with Or
SELECT * FROM Store_Information WHERE Sales > 1000 OR Txn_Date
= 'Jan-08-1999'; Syntax:
Store_Name Sales Txn_Date Los Angeles 1500 Jan-05-1999 Los Angeles 300
Jan-08-1999 Boston 700 Jan-08-1999 Result:
AND or OR
Allows for compound conditions
SELECT "column_name" FROM "table_name" WHERE "simple condition" [AND|OR] "simple condition";
We can use parenthesis ( ) to indicate the order
of the condition.
SELECT Store_Name FROM Store_Information WHERE Sales > 1000 OR (Sales
< 500 AND Sales > 275); Syntax:
Store_Name Los Angeles Result:
Inner Join
INNER JOIN - returns all rows from multiple tables where
the join condition is met.
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON
Orders.CustomerID=Customers.CustomerID; Syntax:
Result:
Different Joins INNER JOIN: Returns all rows when there is
at least one match in BOTH tables LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
Different Joins RIGHT JOIN: Return all rows from the right
table, and the matched rows from the left table FULL JOIN: Return all rows when there is a match in ONE of the tables
WHY KNOW SQL IF I KNOW RAILS?
The Rails ORM is an attempt at an abstraction
The SQL queries that the Rails ORM generates for you
may need to be fine-tuned.
Resources Zed Shaw’s Learn SQL the Hard Way: http://sql.learncodethehardway.org/ book/introduction.html
Use the Index Luke: http://use-the-index-luke.com/sql/table- of-contents