SlideShare a Scribd company logo
Database Management
Essentials
Basic Query Formulation with SQL
Summarized by
github.com/dgkim5360
dgkim5360.tistory.com
SQL Overview
Structured Query Language

A computer language

containing statements of database

definition / control / manipulation
Context

• Stand-alone: Workbench

• Embedded: Django App

Weakness

표준화가 엉망이다: Higher switching cost
Major SQL Statements
Statement Statement Type
CREATE TABLE Definition, Control
CREATE VIEW Definition
CREATE TYPE Definition
SELECT Manipulation
INSERT Manipulation
UPDATE Manipulation
DELETE Manipulation
COMMIT Manipulation
ROLLBACK Manipulation
CREATE TRIGGER Control, Manipulation
GRANT Control
REVOKE Control
SELECT Statement
Introduction
SELECT <list-of-column-expression>

FROM <list-of-tables-and-join-expression>

WHERE <list-of-logical-expression-for-rows>

ORDER BY <list-of-sorting-specifications>

;
Additional Keywords

•AND, OR
•DISTINCT: Remove duplicated rows
•AS: Rename a column
•LIKE: Inexact string matching

DATE type에는 사용하지 말자

Treat DATE as numeric, not text
•BETWEEN AND
•IS NULL: Testing a lack of value
Portability Issue

e.g. Different date functions in

• Oracle: to_char, to_string
• MySQL: date_format
JOIN Operator
• Builds a new table by combining rows

from two tables that match on a join condition

• Unqualified Columns

• Qualified Column? 특정 테이블에 속한 column

• e.g. PK, FK

• EQUI-JOIN (Equality Join)

• 같은 unqualified column을 join column으로 맞춘다

• 보통 PK - FK 간의 연결을 주로 볼 수 있음
Using JOIN in SELECT
Cross-Product Style

SELECT
OfferNo,
CourseNo,
FacFirstName,
FacLastName
FROM Offering, Faculty
WHERE OffTerm = 'FALL'
AND OffYear = 2016
AND FacRank = 'ASST'
AND CourseNo LIKE 'IS%'
AND Faculty.FacNo = Offering.FacNo
;
Join Operator Style

SELECT
OfferNo,
CourseNo,
FacFirstName,
FacLastName
FROM Offering
INNER JOIN Faculty
ON Faculty.FacNo = Offering.FacNo
WHERE OffTerm = 'FALL'
AND OffYear = 2016
AND FacRank = 'ASST'
AND CourseNo LIKE 'IS%'
• N-1 JOIN conditions for N-table JOIN

• 이를 위반하게 되면 심각한 오류가 발생한다.

• 정확하지 않은 결과

• 높은 수준의 자원 소비

• Name Qualification 필요
GROUP BY Clause
Row Summaries

SELECT StdMajor, AVG(StdGPA) as AvgGPA
FROM Student
WHERE StdClass IN ('JR', 'SR')
GROUP BY StdMajor
HAVING AVG(StdGPA) > 3.1
;
Query Clause Evaluation Order

• Row Operations

•FROM
•WHERE
• Group Operations (오직 한 번만 일어남)

•GROUP BY
•HAVING
• Final Operations for Results

•ORDER BY
•SELECT
작은 테이블로 연습하세요

More Related Content

PPT
Sql 2006
PPT
SQL200.1 Module 1
PPTX
Xml part1
PPTX
Introduction to CSS
PPTX
Xml part3
DOCX
Oracle 11g developer on linux training in bangalore
PPTX
Xml part2
PPTX
Introduction to SQL
Sql 2006
SQL200.1 Module 1
Xml part1
Introduction to CSS
Xml part3
Oracle 11g developer on linux training in bangalore
Xml part2
Introduction to SQL

What's hot (19)

PDF
Sql server 2016 queries
PPTX
SQL Assessment Command Statements
PDF
Web Design Course: CSS lecture 1
PPTX
Xml part4
PDF
"Getting Started with XSLT" presentation slides
PPT
Sql server T-sql basics ppt-3
PDF
Web Design Course: CSS lecture 5
PPTX
SQL Fundamentals
PDF
Web Design Course: CSS lecture 2
PPTX
PPT
ORACLE PL SQL
PPT
Chapter 4a cascade style sheet css
PPT
SQL- Introduction to PL/SQL
PDF
Sql tutorial
PPTX
Introduction to SQL (for Chicago Booth MBA technology club)
PDF
Cmsc 100 xhtml and css
PPTX
Web Engineering - Introduction to CSS
PPTX
Intro to T-SQL – 2nd session
Sql server 2016 queries
SQL Assessment Command Statements
Web Design Course: CSS lecture 1
Xml part4
"Getting Started with XSLT" presentation slides
Sql server T-sql basics ppt-3
Web Design Course: CSS lecture 5
SQL Fundamentals
Web Design Course: CSS lecture 2
ORACLE PL SQL
Chapter 4a cascade style sheet css
SQL- Introduction to PL/SQL
Sql tutorial
Introduction to SQL (for Chicago Booth MBA technology club)
Cmsc 100 xhtml and css
Web Engineering - Introduction to CSS
Intro to T-SQL – 2nd session
Ad

Similar to Database Management Essentials: Module 4 Basic Query Formulation with SQL (6)

PPTX
SQL_Presentation.ppt basic version 12.32
PPTX
SQL 쿼리를 AWS DynamoDB에서 (CLI)로 사용해 볼까요?
PDF
제 8회 엑셈 수요 세미나 자료 연구컨텐츠팀
PPTX
Data Manipulation Language
PDF
MySQL Create Table
PPT
Database queries
SQL_Presentation.ppt basic version 12.32
SQL 쿼리를 AWS DynamoDB에서 (CLI)로 사용해 볼까요?
제 8회 엑셈 수요 세미나 자료 연구컨텐츠팀
Data Manipulation Language
MySQL Create Table
Database queries
Ad

Recently uploaded (20)

PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
composite construction of structures.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Well-logging-methods_new................
PDF
PPT on Performance Review to get promotions
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Embodied AI: Ushering in the Next Era of Intelligent Systems
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Lecture Notes Electrical Wiring System Components
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Internet of Things (IOT) - A guide to understanding
Foundation to blockchain - A guide to Blockchain Tech
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
composite construction of structures.pdf
bas. eng. economics group 4 presentation 1.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Mechanical Engineering MATERIALS Selection
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Well-logging-methods_new................
PPT on Performance Review to get promotions
Operating System & Kernel Study Guide-1 - converted.pdf

Database Management Essentials: Module 4 Basic Query Formulation with SQL

  • 1. Database Management Essentials Basic Query Formulation with SQL Summarized by github.com/dgkim5360 dgkim5360.tistory.com
  • 2. SQL Overview Structured Query Language A computer language
 containing statements of database
 definition / control / manipulation Context • Stand-alone: Workbench • Embedded: Django App Weakness 표준화가 엉망이다: Higher switching cost Major SQL Statements Statement Statement Type CREATE TABLE Definition, Control CREATE VIEW Definition CREATE TYPE Definition SELECT Manipulation INSERT Manipulation UPDATE Manipulation DELETE Manipulation COMMIT Manipulation ROLLBACK Manipulation CREATE TRIGGER Control, Manipulation GRANT Control REVOKE Control
  • 3. SELECT Statement Introduction SELECT <list-of-column-expression>
 FROM <list-of-tables-and-join-expression>
 WHERE <list-of-logical-expression-for-rows>
 ORDER BY <list-of-sorting-specifications>
 ; Additional Keywords •AND, OR •DISTINCT: Remove duplicated rows •AS: Rename a column •LIKE: Inexact string matching
 DATE type에는 사용하지 말자
 Treat DATE as numeric, not text •BETWEEN AND •IS NULL: Testing a lack of value Portability Issue e.g. Different date functions in • Oracle: to_char, to_string • MySQL: date_format
  • 4. JOIN Operator • Builds a new table by combining rows
 from two tables that match on a join condition • Unqualified Columns • Qualified Column? 특정 테이블에 속한 column • e.g. PK, FK • EQUI-JOIN (Equality Join) • 같은 unqualified column을 join column으로 맞춘다 • 보통 PK - FK 간의 연결을 주로 볼 수 있음
  • 5. Using JOIN in SELECT Cross-Product Style SELECT OfferNo, CourseNo, FacFirstName, FacLastName FROM Offering, Faculty WHERE OffTerm = 'FALL' AND OffYear = 2016 AND FacRank = 'ASST' AND CourseNo LIKE 'IS%' AND Faculty.FacNo = Offering.FacNo ; Join Operator Style SELECT OfferNo, CourseNo, FacFirstName, FacLastName FROM Offering INNER JOIN Faculty ON Faculty.FacNo = Offering.FacNo WHERE OffTerm = 'FALL' AND OffYear = 2016 AND FacRank = 'ASST' AND CourseNo LIKE 'IS%' • N-1 JOIN conditions for N-table JOIN • 이를 위반하게 되면 심각한 오류가 발생한다. • 정확하지 않은 결과 • 높은 수준의 자원 소비 • Name Qualification 필요
  • 6. GROUP BY Clause Row Summaries SELECT StdMajor, AVG(StdGPA) as AvgGPA FROM Student WHERE StdClass IN ('JR', 'SR') GROUP BY StdMajor HAVING AVG(StdGPA) > 3.1 ; Query Clause Evaluation Order • Row Operations •FROM •WHERE • Group Operations (오직 한 번만 일어남) •GROUP BY •HAVING • Final Operations for Results •ORDER BY •SELECT 작은 테이블로 연습하세요