SlideShare ist ein Scribd-Unternehmen logo
1 von 69
 
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],SQL ADVANCED ,[object Object],[object Object],[object Object],[object Object],[object Object]
Introduction to SQL ,[object Object],[object Object],What is SQL? ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object]
[object Object],[object Object],CREATE DATABASE database_name   ,[object Object],[object Object],CREATE TABLE table_name ( column_name1 data_type,  column_name2 data_type, ....... )   SQL Create The  CREATE  statement is used to create a new database, table or index.
Some Basic Data Types SQL Create Data Type Description integer (size) int (size) smallint (size) tinyint (size) Hold integers only. The maximum number of digits are specified in parenthesis. Decimal (size, d) numeric (size, d) Hold numbers with fractions. The maximum number of digits are specified in "size". The maximum number of digits to the right of the decimal is specified in "d".
Some Basic Data Types (cont.) SQL Create char (size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. varchar (size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. date (yyyymmdd) Holds a date
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ALTER Statement
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DROP Statement
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
INSERT Statement
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
UPDATE Statement
[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
DELETE Statement
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
SELECT Statement
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object]
Selection Projection Table 1 Table 2 Table 1 Table 1 Join
[object Object],[object Object],SELECT [DISTINCT] {*,  column  [ alias ],...} FROM table;
[object Object],[object Object],[object Object],[object Object],[object Object]
DEPTNO DNAME  LOC --------- -------------- ------------- 10 ACCOUNTING  MALOLOS 20 RESEARCH  HAGONOY 30 SALES  CALUMPIT 40 OPERATIONS  PULILAN SQL> SELECT * 2  FROM  dept;
DEPTNO LOC --------- ------------- 10 MALOLOS 20 HAGONOY 30 CALUMPIT 40 PULILAN SQL> SELECT deptno, loc 2  FROM  dept;
[object Object],Operator + - * /  Description Add Subtract  Multiply  Divide
SQL> SELECT ename, sal, sal+300 2  FROM emp; ENAME  SAL  SAL+300 ---------- --------- --------- ROMEL 20000   20300 JOI 10000   10300 JANE 5000   5300 ANDY 5875  6175 RANDY 11784   12084 MARK 9775   10075 ... 10 rows selected.
[object Object],[object Object],[object Object],* / + _
SQL> SELECT ename, sal, 12*sal+100 2  FROM  emp; ENAME  SAL 12*SAL+100 ---------- --------- ---------- ROMEL 20000   240100 JOI 10000   120100 JANE 5000   60100 ANDY 5875  70600 RANDY 11784   141508 ... 10 rows selected.
SQL> SELECT ename, sal, 12*(sal+100) 2  FROM  emp; ENAME  SAL 12*(SAL+100) ---------- --------- ----------- ROMEL 20000   241200 JOI 10000   121200 JANE 5000   61200 ANDY 5875  71700 RANDY 11784   142608 ... 10 rows selected.
[object Object],[object Object],ENAME  JOB  SAL  COMM ---------- --------- --------- --------- ROMEL   PRESIDENT 20000   NULL JOI   SALES MANAGER 10000   1000 ... RANDY   HEAD ACCOUNTANT 11784   NULL 10 rows selected. SQL> SELECT ename, job, sal, comm 2  FROM  emp;
[object Object],SQL> select ename, 12*sal+comm  2  from  emp 3  WHERE  ename=‘ROMEL'; ENAME  12*SAL+COMM  ---------- ----------- KING NULL
[object Object],[object Object],[object Object],[object Object]
SQL> SELECT ename AS name, sal salary 2  FROM  emp; NAME  SALARY ------------- --------- ... SQL> SELECT ename  "Name", 2  sal*12 "Annual Salary" 3  FROM  emp; Name  Annual Salary ------------- ------------- ...
[object Object],[object Object],[object Object]
SQL> SELECT ename + job AS "Employees" 2  FROM  emp; Employees ------------------- ROMELPRESIDENT JOISALES MANAGER JANESALES REPRESENTATIVE ANDYSALES REPRESENTATIVE RANDYHEAD ACCOUNTANT ... 10 rows selected.
[object Object],[object Object],[object Object]
Employee Details ------------------------- ... 10 rows selected. SQL> SELECT ename + ' is a ‘ + job  2   AS "Employee Details" 3  FROM  emp; ROMEL is a PRESIDENT JOI is a SALES MANAGER JANE is a SALES REPRESENTATIVE ANDY is a SALES REPRESENTATIVE RANDY is a HEAD ACCOUNTANT
[object Object],SQL> SELECT deptno 2  FROM  emp; DEPTNO --------- 10 30 10 40 ... 14 rows selected.
Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SQL> SELECT DISTINCT deptno 2  FROM  emp; DEPTNO --------- 10 30 40
SQL statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],SQL buffer SQL*Plus commands SQL*Plus buffer
"…retrieve all employees in department 30" EMP EMPNO  ENAME  JOB  ...  DEPTNO  1001 ROMEL PRESIDENT   40 1002 JOI SALES M...  30 1003 JANE SALES REP    30 . . . 1006 MARK ACCOUN..   10   ... EMP EMPNO  ENAME  JOB  ...  DEPTNO  1002 JOI SALES M...  30 1003 JANE SALES REP    30 . . .
[object Object],[object Object],SELECT [DISTINCT] {*|  column  [ alias ], ...} FROM  table [WHERE condition(s) ];
SQL> SELECT ename, deptno 2  FROM  emp 3  WHERE  deptno=10; ENAME  DEPTNO ---------- --------- --------- RANDY   10 MARK   10 JESSA   10
Operator = > >= < <= <> Meaning Equal to Greater than  Greater than or equal to  Less than  Less than or equal to Not equal to
SQL> SELECT ename,comm 2  FROM  emp 3  WHERE  comm>=700; ENAME  COMM ---------- ---------  MARTIN  1000
Operator BETWEEN ...AND... IN(list) LIKE IS NULL Meaning Between two values (inclusive) Match any of a list of values  Match a character pattern  Is a null value
[object Object],ENAME  SAL ---------- --------- JOI 10000 JANE 5000 ANDY 5875 MARK 9775 RIZZA 9798 DAVID 6897 SQL> SELECT ename, sal 2  FROM  emp 3  WHERE sal BETWEEN 5000 AND 10000; Lower limit Higher limit
[object Object],SQL> SELECT ename, deptno 2  FROM  emp 3  WHERE deptno IN (10, 40);   ENAME  deptno ---------  ---------   ROMEL   40   RANDY   10   MARK   10   RIZZA   40
[object Object],[object Object],[object Object],[object Object],SQL> SELECT ename 2  FROM  emp 3  WHERE ename LIKE ‘R%';
[object Object],[object Object],SQL> SELECT ename 2  FROM emp 3  WHERE ename LIKE '_O%'; ENAME ----------  ROMEL JOI
[object Object],SQL> SELECT  ename, mgr 2  FROM  emp 3  WHERE  mgr IS NULL; ENAME  MGR ---------- --------- ROMEL NULL
Operator AND OR NOT Meaning Returns TRUE if  both  component conditions are TRUE Returns TRUE if  either  component condition is TRUE Returns TRUE if the following  condition is FALSE

Weitere ähnliche Inhalte

Was ist angesagt?

Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
ISsoft
 

Was ist angesagt? (20)

Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
 
Query
QueryQuery
Query
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Dbms record
Dbms recordDbms record
Dbms record
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Les02
Les02Les02
Les02
 
MY SQL
MY SQLMY SQL
MY SQL
 
Sql
SqlSql
Sql
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
 
Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Les02
Les02Les02
Les02
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Sql
SqlSql
Sql
 
Les13
Les13Les13
Les13
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 

Ähnlich wie Select To Order By (20)

Les01
Les01Les01
Les01
 
Les01
Les01Les01
Les01
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Les09
Les09Les09
Les09
 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Les10
Les10Les10
Les10
 
Sql intro
Sql introSql intro
Sql intro
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Sql
SqlSql
Sql
 
SQL
SQLSQL
SQL
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
SQL (1).pptx
SQL (1).pptxSQL (1).pptx
SQL (1).pptx
 
Basic SQL Statments
Basic SQL StatmentsBasic SQL Statments
Basic SQL Statments
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Select To Order By

  • 1.  
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Some Basic Data Types SQL Create Data Type Description integer (size) int (size) smallint (size) tinyint (size) Hold integers only. The maximum number of digits are specified in parenthesis. Decimal (size, d) numeric (size, d) Hold numbers with fractions. The maximum number of digits are specified in &quot;size&quot;. The maximum number of digits to the right of the decimal is specified in &quot;d&quot;.
  • 11. Some Basic Data Types (cont.) SQL Create char (size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. varchar (size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. date (yyyymmdd) Holds a date
  • 12.
  • 13.
  • 14.
  • 15.
  • 17.
  • 18.
  • 20.
  • 21.
  • 23.
  • 24.
  • 25.
  • 27.
  • 28.
  • 30.
  • 31.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. Selection Projection Table 1 Table 2 Table 1 Table 1 Join
  • 38.
  • 39.
  • 40. DEPTNO DNAME LOC --------- -------------- ------------- 10 ACCOUNTING MALOLOS 20 RESEARCH HAGONOY 30 SALES CALUMPIT 40 OPERATIONS PULILAN SQL> SELECT * 2 FROM dept;
  • 41. DEPTNO LOC --------- ------------- 10 MALOLOS 20 HAGONOY 30 CALUMPIT 40 PULILAN SQL> SELECT deptno, loc 2 FROM dept;
  • 42.
  • 43. SQL> SELECT ename, sal, sal+300 2 FROM emp; ENAME SAL SAL+300 ---------- --------- --------- ROMEL 20000 20300 JOI 10000 10300 JANE 5000 5300 ANDY 5875 6175 RANDY 11784 12084 MARK 9775 10075 ... 10 rows selected.
  • 44.
  • 45. SQL> SELECT ename, sal, 12*sal+100 2 FROM emp; ENAME SAL 12*SAL+100 ---------- --------- ---------- ROMEL 20000 240100 JOI 10000 120100 JANE 5000 60100 ANDY 5875 70600 RANDY 11784 141508 ... 10 rows selected.
  • 46. SQL> SELECT ename, sal, 12*(sal+100) 2 FROM emp; ENAME SAL 12*(SAL+100) ---------- --------- ----------- ROMEL 20000 241200 JOI 10000 121200 JANE 5000 61200 ANDY 5875 71700 RANDY 11784 142608 ... 10 rows selected.
  • 47.
  • 48.
  • 49.
  • 50. SQL> SELECT ename AS name, sal salary 2 FROM emp; NAME SALARY ------------- --------- ... SQL> SELECT ename &quot;Name&quot;, 2 sal*12 &quot;Annual Salary&quot; 3 FROM emp; Name Annual Salary ------------- ------------- ...
  • 51.
  • 52. SQL> SELECT ename + job AS &quot;Employees&quot; 2 FROM emp; Employees ------------------- ROMELPRESIDENT JOISALES MANAGER JANESALES REPRESENTATIVE ANDYSALES REPRESENTATIVE RANDYHEAD ACCOUNTANT ... 10 rows selected.
  • 53.
  • 54. Employee Details ------------------------- ... 10 rows selected. SQL> SELECT ename + ' is a ‘ + job 2 AS &quot;Employee Details&quot; 3 FROM emp; ROMEL is a PRESIDENT JOI is a SALES MANAGER JANE is a SALES REPRESENTATIVE ANDY is a SALES REPRESENTATIVE RANDY is a HEAD ACCOUNTANT
  • 55.
  • 56. Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SQL> SELECT DISTINCT deptno 2 FROM emp; DEPTNO --------- 10 30 40
  • 57.
  • 58. &quot;…retrieve all employees in department 30&quot; EMP EMPNO ENAME JOB ... DEPTNO 1001 ROMEL PRESIDENT 40 1002 JOI SALES M... 30 1003 JANE SALES REP 30 . . . 1006 MARK ACCOUN.. 10 ... EMP EMPNO ENAME JOB ... DEPTNO 1002 JOI SALES M... 30 1003 JANE SALES REP 30 . . .
  • 59.
  • 60. SQL> SELECT ename, deptno 2 FROM emp 3 WHERE deptno=10; ENAME DEPTNO ---------- --------- --------- RANDY 10 MARK 10 JESSA 10
  • 61. Operator = > >= < <= <> Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to
  • 62. SQL> SELECT ename,comm 2 FROM emp 3 WHERE comm>=700; ENAME COMM ---------- --------- MARTIN 1000
  • 63. Operator BETWEEN ...AND... IN(list) LIKE IS NULL Meaning Between two values (inclusive) Match any of a list of values Match a character pattern Is a null value
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69. Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns TRUE if the following condition is FALSE