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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
kickinbahk
January 06, 2016
Technology
150
0
Share
SQL Basics - RRUG 1/6/2016
Overview of SQL and basic syntax.
kickinbahk
January 06, 2016
More Decks by kickinbahk
See All by kickinbahk
OptOutside App
kickinbahk
0
78
Ensuring The Happy Path - Mobile Dev + Test
kickinbahk
0
180
Optionals, Protocols and Extensions - Swift by Example - SoCal Code Camp '16
kickinbahk
0
150
Intro to Elm - RRuG 05/2016
kickinbahk
0
190
WebSockets Intro - Riverside Ruby Group - 03/2016
kickinbahk
0
110
ES2015 and Your Rails App - Riverside Ruby Group
kickinbahk
0
250
Demystifying the Wizardry of Regular Expressions - LV DotNet Meetup - 01/2016
kickinbahk
0
240
Demystifying the Wizardry of Regular Expressions - SoCal Code Camp '15 - LA
kickinbahk
0
270
Becoming a Polyglot Programmer through the Eyes of a Freelance Musician - SoCal Code Camp 15 - LA
kickinbahk
0
160
Other Decks in Technology
See All in Technology
Hooks, Filters & Now Context: Why MCPs Are the “Hooks” of the AI Era
miriamschwab
0
130
Introduction to Bill One Development Engineer
sansan33
PRO
0
400
Databricksを用いたセキュアなデータ基盤構築とAIプロダクトへの応用.pdf
pkshadeck
PRO
0
290
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
16k
さくらのクラウドでつくるCloudNative Daysのオブザーバビリティ基盤
b1gb4by
0
150
AIを活用したアクセシビリティ改善フロー
degudegu2510
1
170
プロジェクトマネジメントは AIでどう変わるか?
mkg5383
0
200
BIツール「Omni」の紹介 @Snowflake中部UG
sagara
0
270
20260410 - CNTUG meetup #72 - DiskImage Builder 介紹:以 Kubespray CI 打造 RockyLinux 10 Cloud Image 為例
tico88612
0
120
幾億の壁を超えて/Beyond Countless Walls(JP)
ikuodanaka
0
100
暗黙知について一歩踏み込んで考える - 暗黙知の4タイプと暗黙考・暗黙動へ
masayamoriofficial
0
1.3k
GitHub Copilotを極める会 - 開発者のための活用術
findy_eventslides
6
4k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
140
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
260
The Language of Interfaces
destraynor
162
26k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
340
Building Adaptive Systems
keathley
44
3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
97
How GitHub (no longer) Works
holman
316
150k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
670
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