SlideShare a Scribd company logo
Writing Basic SQL Statements
Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement Differentiate between SQL statements and SQL*Plus commands
Capabilities of SQL SELECT Statements Projection Selection Table 1 Table 1 Join Table 2 Table 1
Basic SELECT Statement SELECT	[DISTINCT] {*, column [alias],...} FROMtable; SELECT identifies what columns. FROM identifies which table.
Writing SQL Statements SQL statements are not case sensitive.  SQL statements can be on one ormore lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Tabs and indents are used to enhance readability.
Selecting All Columns SQL> SELECT * 2  FROM dept;    DEPTNO DNAME          LOC --------- -------------- ------------- 10 ACCOUNTING     NEW YORK 20 RESEARCH       DALLAS 30 SALES          CHICAGO 40 OPERATIONS     BOSTON
Selecting Specific Columns SQL> SELECT deptno, loc 2  FROM   dept;    DEPTNO LOC --------- ------------- 10 NEW YORK 20 DALLAS 30 CHICAGO 40 BOSTON
Column Heading Defaults Default justification Left: Date and character data Right: Numeric data Default display: Uppercase
Arithmetic Expressions Create expressions on NUMBER and DATE data by using arithmetic operators. Operator + - *       /       	 Description Add Subtract  Multiply  Divide
Using Arithmetic Operators SQL> SELECT ename, sal, sal+300 2  FROMemp; ENAME            SAL   SAL+300 ---------- --------- --------- KING            50005300 BLAKE           28503150 CLARK           24502750 JONES           29753275 MARTIN          12501550 ALLEN           16001900 ... 14 rows selected.
Operator Precedence _ / + * Multiplication and division take priority over addition and subtraction. Operators of the same priority are evaluated from left to right. Parentheses are used to force prioritized evaluation and to clarify statements.
Operator Precedence SQL> SELECT ename, sal, 12*sal+100 2  FROM   emp; ENAME            SAL 12*SAL+100 ---------- --------- ---------- KING            500060100 BLAKE           285034300 CLARK           245029500 JONES           297535800 MARTIN          125015100 ALLEN           160019300 ... 14 rows selected.
Using Parentheses SQL> SELECT ename, sal, 12*(sal+100) 2  FROM   emp; ENAME            SAL 12*(SAL+100) ---------- --------- ----------- KING            500061200 BLAKE           285035400 CLARK           245030600 JONES           297536900 MARTIN          125016200 ... 14 rows selected.
Defining a Null Value A null is a value that is unavailable, unassigned, unknown, or inapplicable. A null is not the same as zero or a blank space. SQL> SELECT ename, job, comm 2  FROMemp; ENAME      JOB            COMM ---------- --------- --------- KING       PRESIDENT BLAKE      MANAGER ... TURNER     SALESMAN          0 ... 14 rows selected.
Null Values in Arithmetic Expressions Arithmetic expressions containing a null value evaluate to null. SQL> select ename, 12*sal+comm  2  from   emp 3  WHERE  ename='KING'; ENAME      12*SAL+COMM  ---------- ----------- KING
Defining a Column Alias Renames a column heading Is useful with calculations Immediately follows column name; optional AS keyword between column name and alias Requires double quotation marks if it contains spaces or special characters or is case sensitive
Using Column Aliases Name          Annual Salary ------------- -------------... SQL> SELECT ename AS name, sal salary 2  FROM   emp; NAME             SALARY ------------- ---------... SQL> SELECT ename "Name", 2         sal*12 "Annual Salary" 3  FROM   emp;
Concatenation Operator Concatenates columns or character strings to other columns  Is represented by two vertical bars (||) Creates a resultant column that is a character expression
Using the Concatenation Operator SQL> SELECTename||job AS "Employees" 2  FROM emp; Employees ------------------- KINGPRESIDENT BLAKEMANAGER CLARKMANAGER JONESMANAGER MARTINSALESMAN ALLENSALESMAN ... 14 rows selected.
Literal Character Strings A literal is a character, expression, or number included in the SELECT list. Date and character literal values must be enclosed within single quotation marks. Each character string is output once for each row returned.
Using Literal Character Strings SQL> SELECT ename||' '||'is a'||' '||job  2AS "Employee Details" 3  FROM   emp; Employee Details ------------------------- KING is a PRESIDENT BLAKE is a MANAGER CLARK is a MANAGER JONES is a MANAGER MARTIN is a SALESMAN ... 14 rows selected.
Duplicate Rows The default display of queries is all rows, including duplicate rows. SQL> SELECT deptno 2  FROM   emp;    DEPTNO --------- 10 30 10 20 ... 14 rows selected.
Eliminating Duplicate Rows Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SQL> SELECT DISTINCT deptno 2  FROM   emp;    DEPTNO --------- 10 20 30
SQL and SQL*Plus Interaction SQL Statements SQL Statements Server Query Results SQL*Plus  Commands Formatted Report Buffer SQL*Plus
SQL Statements Versus SQL*Plus Commands  SQL  ,[object Object]
ANSI standard
Keyword cannot be abbreviated
Statements manipulate data and table definitions in the  databaseSQL*Plus ,[object Object]
Oracle proprietary
Keywords can be abbreviated
Commands do not allow manipulation of values in the databaseSQL statements SQL buffer SQL*Plus commands SQL*Plus buffer
Log in to SQL*Plus. Describe the table structure. Edit your SQL statement. Execute SQL from SQL*Plus. Save SQL statements to files and append SQL statements to files. Execute saved files. Load commands from file to bufferto edit. Overview of SQL*Plus
Logging In to SQL*Plus From Windows environment: From command line:  sqlplus [username[/password                 [@database]]]
Displaying Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table. DESC[RIBE] tablename

More Related Content

What's hot

SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12Umair Amjad
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known Facets
Andrej Pashchenko
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
Sachin Shukla
 
Les05[1]Aggregating Data Using Group Functions
Les05[1]Aggregating Data  Using Group FunctionsLes05[1]Aggregating Data  Using Group Functions
Les05[1]Aggregating Data Using Group Functions
siavosh kaviani
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
Hitesh Mohapatra
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2Umair Amjad
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
Andrej Pashchenko
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
Angel G Diaz
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1Umair Amjad
 
Single row functions
Single row functionsSingle row functions
Single row functions
Balqees Al.Mubarak
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
Krizia Capacio
 

What's hot (20)

Les03
Les03Les03
Les03
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Les01
Les01Les01
Les01
 
Les12
Les12Les12
Les12
 
Les10
Les10Les10
Les10
 
Les11
Les11Les11
Les11
 
Les09
Les09Les09
Les09
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known Facets
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
Les05[1]Aggregating Data Using Group Functions
Les05[1]Aggregating Data  Using Group FunctionsLes05[1]Aggregating Data  Using Group Functions
Les05[1]Aggregating Data Using Group Functions
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Les02
Les02Les02
Les02
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 

Viewers also liked

SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Salman Memon
 
No sql and sql - open analytics summit
No sql and sql - open analytics summitNo sql and sql - open analytics summit
No sql and sql - open analytics summitOpen Analytics
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handoutsjhe04
 
Sql basics joi ns and common commands (1)
Sql basics  joi ns and common commands (1)Sql basics  joi ns and common commands (1)
Sql basics joi ns and common commands (1)johnnygoodman
 
Sql Basic Selects
Sql Basic SelectsSql Basic Selects
Sql Basic Selects
Bob Litsinger
 
What Is SQL?
What Is SQL?What Is SQL?
What Is SQL?
QATestLab
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
Varun A M
 
php basic sql
php basic sqlphp basic sql
php basic sql
tumetr1
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
Vikas Gupta
 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
Amit Kumar Singh
 
SQL Basic Queries
SQL Basic Queries SQL Basic Queries
SQL Basic Queries
Pranil Dukare
 
개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축
정해 이
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝
정해 이
 
Sql Server 2012
Sql Server 2012Sql Server 2012
Sql Server 2012
Performics.Convonix
 

Viewers also liked (20)

SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
 
Introduction to mysql part 2
Introduction to mysql part 2Introduction to mysql part 2
Introduction to mysql part 2
 
No sql and sql - open analytics summit
No sql and sql - open analytics summitNo sql and sql - open analytics summit
No sql and sql - open analytics summit
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Sql basics joi ns and common commands (1)
Sql basics  joi ns and common commands (1)Sql basics  joi ns and common commands (1)
Sql basics joi ns and common commands (1)
 
Sql Basic Selects
Sql Basic SelectsSql Basic Selects
Sql Basic Selects
 
1 ddl
1 ddl1 ddl
1 ddl
 
Sql basics
Sql basicsSql basics
Sql basics
 
What Is SQL?
What Is SQL?What Is SQL?
What Is SQL?
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
 
php basic sql
php basic sqlphp basic sql
php basic sql
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
 
SQL Basic Queries
SQL Basic Queries SQL Basic Queries
SQL Basic Queries
 
개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝
 
Sql Server 2012
Sql Server 2012Sql Server 2012
Sql Server 2012
 

Similar to Les01 Writing Basic Sql Statements

Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oraclesuman1248
 
CHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxCHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptx
MuhammadSheraz836877
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01
Angel G Diaz
 
Sql statments c ha p# 1
Sql statments c ha p# 1Sql statments c ha p# 1
Sql statments c ha p# 1Nargis Ehsan
 
Lecture02_IDB.pptx
Lecture02_IDB.pptxLecture02_IDB.pptx
Lecture02_IDB.pptx
MostafizurRahaman41
 
Les01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL StatementsLes01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL Statements
siavosh kaviani
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
N.Jagadish Kumar
 
Les01.ppt
Les01.pptLes01.ppt
Les01.ppt
sanasaeed84
 
Les01.pptx
Les01.pptxLes01.pptx
Les01.pptx
NishaTariq1
 
Sqlplus
SqlplusSqlplus
Sqlplus
dillip kar
 
Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oraclesuman1248
 
Sql intro
Sql introSql intro
Sql introglubox
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
Mohamed Moustafa
 
Les01
Les01Les01
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Achmad Solichin
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
Anjac
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
Subash T
 

Similar to Les01 Writing Basic Sql Statements (20)

Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
 
CHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxCHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptx
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01
 
Sql statments c ha p# 1
Sql statments c ha p# 1Sql statments c ha p# 1
Sql statments c ha p# 1
 
Basic sql statements
Basic sql statementsBasic sql statements
Basic sql statements
 
Lecture02_IDB.pptx
Lecture02_IDB.pptxLecture02_IDB.pptx
Lecture02_IDB.pptx
 
Les01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL StatementsLes01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL Statements
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Les01.ppt
Les01.pptLes01.ppt
Les01.ppt
 
Les01.pptx
Les01.pptxLes01.pptx
Les01.pptx
 
Sqlplus
SqlplusSqlplus
Sqlplus
 
Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oracle
 
Sql intro
Sql introSql intro
Sql intro
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
 
Les01
Les01Les01
Les01
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
 
Sql 3
Sql 3Sql 3
Sql 3
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 

Recently uploaded

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

Les01 Writing Basic Sql Statements

  • 1. Writing Basic SQL Statements
  • 2. Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement Differentiate between SQL statements and SQL*Plus commands
  • 3. Capabilities of SQL SELECT Statements Projection Selection Table 1 Table 1 Join Table 2 Table 1
  • 4. Basic SELECT Statement SELECT [DISTINCT] {*, column [alias],...} FROMtable; SELECT identifies what columns. FROM identifies which table.
  • 5. Writing SQL Statements SQL statements are not case sensitive. SQL statements can be on one ormore lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Tabs and indents are used to enhance readability.
  • 6. Selecting All Columns SQL> SELECT * 2 FROM dept; DEPTNO DNAME LOC --------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON
  • 7. Selecting Specific Columns SQL> SELECT deptno, loc 2 FROM dept; DEPTNO LOC --------- ------------- 10 NEW YORK 20 DALLAS 30 CHICAGO 40 BOSTON
  • 8. Column Heading Defaults Default justification Left: Date and character data Right: Numeric data Default display: Uppercase
  • 9. Arithmetic Expressions Create expressions on NUMBER and DATE data by using arithmetic operators. Operator + - * / Description Add Subtract Multiply Divide
  • 10. Using Arithmetic Operators SQL> SELECT ename, sal, sal+300 2 FROMemp; ENAME SAL SAL+300 ---------- --------- --------- KING 50005300 BLAKE 28503150 CLARK 24502750 JONES 29753275 MARTIN 12501550 ALLEN 16001900 ... 14 rows selected.
  • 11. Operator Precedence _ / + * Multiplication and division take priority over addition and subtraction. Operators of the same priority are evaluated from left to right. Parentheses are used to force prioritized evaluation and to clarify statements.
  • 12. Operator Precedence SQL> SELECT ename, sal, 12*sal+100 2 FROM emp; ENAME SAL 12*SAL+100 ---------- --------- ---------- KING 500060100 BLAKE 285034300 CLARK 245029500 JONES 297535800 MARTIN 125015100 ALLEN 160019300 ... 14 rows selected.
  • 13. Using Parentheses SQL> SELECT ename, sal, 12*(sal+100) 2 FROM emp; ENAME SAL 12*(SAL+100) ---------- --------- ----------- KING 500061200 BLAKE 285035400 CLARK 245030600 JONES 297536900 MARTIN 125016200 ... 14 rows selected.
  • 14. Defining a Null Value A null is a value that is unavailable, unassigned, unknown, or inapplicable. A null is not the same as zero or a blank space. SQL> SELECT ename, job, comm 2 FROMemp; ENAME JOB COMM ---------- --------- --------- KING PRESIDENT BLAKE MANAGER ... TURNER SALESMAN 0 ... 14 rows selected.
  • 15. Null Values in Arithmetic Expressions Arithmetic expressions containing a null value evaluate to null. SQL> select ename, 12*sal+comm 2 from emp 3 WHERE ename='KING'; ENAME 12*SAL+COMM ---------- ----------- KING
  • 16. Defining a Column Alias Renames a column heading Is useful with calculations Immediately follows column name; optional AS keyword between column name and alias Requires double quotation marks if it contains spaces or special characters or is case sensitive
  • 17. Using Column Aliases Name Annual Salary ------------- -------------... SQL> SELECT ename AS name, sal salary 2 FROM emp; NAME SALARY ------------- ---------... SQL> SELECT ename "Name", 2 sal*12 "Annual Salary" 3 FROM emp;
  • 18. Concatenation Operator Concatenates columns or character strings to other columns Is represented by two vertical bars (||) Creates a resultant column that is a character expression
  • 19. Using the Concatenation Operator SQL> SELECTename||job AS "Employees" 2 FROM emp; Employees ------------------- KINGPRESIDENT BLAKEMANAGER CLARKMANAGER JONESMANAGER MARTINSALESMAN ALLENSALESMAN ... 14 rows selected.
  • 20. Literal Character Strings A literal is a character, expression, or number included in the SELECT list. Date and character literal values must be enclosed within single quotation marks. Each character string is output once for each row returned.
  • 21. Using Literal Character Strings SQL> SELECT ename||' '||'is a'||' '||job 2AS "Employee Details" 3 FROM emp; Employee Details ------------------------- KING is a PRESIDENT BLAKE is a MANAGER CLARK is a MANAGER JONES is a MANAGER MARTIN is a SALESMAN ... 14 rows selected.
  • 22. Duplicate Rows The default display of queries is all rows, including duplicate rows. SQL> SELECT deptno 2 FROM emp; DEPTNO --------- 10 30 10 20 ... 14 rows selected.
  • 23. Eliminating Duplicate Rows Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SQL> SELECT DISTINCT deptno 2 FROM emp; DEPTNO --------- 10 20 30
  • 24. SQL and SQL*Plus Interaction SQL Statements SQL Statements Server Query Results SQL*Plus Commands Formatted Report Buffer SQL*Plus
  • 25.
  • 27. Keyword cannot be abbreviated
  • 28.
  • 30. Keywords can be abbreviated
  • 31. Commands do not allow manipulation of values in the databaseSQL statements SQL buffer SQL*Plus commands SQL*Plus buffer
  • 32. Log in to SQL*Plus. Describe the table structure. Edit your SQL statement. Execute SQL from SQL*Plus. Save SQL statements to files and append SQL statements to files. Execute saved files. Load commands from file to bufferto edit. Overview of SQL*Plus
  • 33. Logging In to SQL*Plus From Windows environment: From command line: sqlplus [username[/password [@database]]]
  • 34. Displaying Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table. DESC[RIBE] tablename
  • 35. Displaying Table Structure SQL> DESCRIBE dept Name Null? Type ----------------- -------- ------------ DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13)
  • 36. SQL*Plus Editing Commands A[PPEND] text C[HANGE] / old / new C[HANGE] / text / CL[EAR] BUFF[ER] DEL DEL n DEL m n
  • 37. SQL*Plus Editing Commands I[NPUT] I[NPUT] text L[IST] L[IST] n L[IST] m n R[UN] n ntext 0text
  • 38. SQL*Plus File Commands SAVE filename GET filename START filename @ filename EDIT filename SPOOL filename
  • 39. Summary SELECT [DISTINCT] {*,column [alias],...} FROMtable; Use SQL*Plus as an environment to: Execute SQL statements Edit SQL statements
  • 40. Practice Overview Selecting all data from different tables Describing the structure of tables Performing arithmetic calculations and specifying column names Using SQL*Plus editor