SlideShare una empresa de Scribd logo
1 de 41
SQL for Software Testing
What is SQL?

 SQL stands for Structured Query Language
 SQL lets you access and manipulate databases
 SQL is an ANSI Standard

ANSI: American National Standards Institute
Why we use SQL?
   SQL can execute queries against a database
   SQL can retrieve data from a database
   SQL can insert records in a database
   SQL can update records in a database
   SQL can delete records from a database
   SQL can create new databases
   SQL can create new tables in a database
   SQL can create stored procedures in a database
   SQL can create views in a database
   SQL can set permissions on tables, procedures, and views
What is RDBMS?
RDBMS: Relational Database Management System
*Software that stores and manipulates data arranged in relational database tables.

Common RDBMS that use SQL are:

   Oracle
   Sybase
   Microsoft SQL Server
   Access
DDL
Data Definition Language (DDL) statements are
used to define the database structure or schema.

   CREATE - To create objects in the database
   ALTER - Alters the structure of the database
   DROP - Delete objects from the database
   TRUNCATE - Remove all records from a table,
    including all spaces allocated for the records
    are removed
DML
Data Manipulation Language (DML) statements
are used for managing data within schema
objects.

   SELECT - retrieve data from the a database
   INSERT - insert data into a table
   UPDATE - updates existing data within a table
   DELETE - deletes all records from a table, the
    space for the records remain
SQL Arithmetic Operators
Operator   Description                             Example
+          Addition - Adds values on either side   a+b
           of the operator
-          Subtraction - Subtracts right hand      a–b
           operand from left hand operand

*          Multiplication - Multiplies values on   a*b
           either side of the operator

/          Division - Divides left hand operand by b / a
           right hand operand

%          Modulus - Divides left hand operand     b%a
           by right hand operand and returns
           remainder
SQL Comparison Operators
Operator                                  Description                                                   Example

=          Checks if the value of two operands are equal or not, if yes then            (a = b) is not true.
           condition becomes true.

!=         Checks if the value of two operands are equal or not, if values are not      (a != b) is true.
           equal then condition becomes true.

<>         Checks if the value of two operands are equal or not, if values are not      (a <> b) is true.
           equal then condition becomes true.

>          Checks if the value of left operand is greater than the value of right       (a > b) is not true.
           operand, if yes then condition becomes true.

<          Checks if the value of left operand is less than the value of right          (a < b) is true.
           operand, if yes then condition becomes true.

>=         Checks if the value of left operand is greater than or equal to the value    (a >= b) is not true.
           of right operand, if yes then condition becomes true.

<=         Checks if the value of left operand is less than or equal to the value of    (a <= b) is true.
           right operand, if yes then condition becomes true.

!<         Checks if the value of left operand is not less than the value of right      (a !< b) is false.
           operand, if yes then condition becomes true.

!>         Checks if the value of left operand is not greater than the value of right   (a !> b) is true.
           operand, if yes then condition becomes true.
SQL Logical Operators
     Operator                                  Description
AND             The AND operator allows the existence of multiple conditions in an SQL
                statement's WHERE clause.
BETWEEN         The BETWEEN operator is used to search for values that are within a set
                of values, given the minimum value and the maximum value.
IN              The IN operator is used to compare a value to a list of literal values that
                have been specified.
LIKE            The LIKE operator is used to compare a value to similar values using
                wildcard operators.
NOT             The NOT operator reverses the meaning of the logical operator with
                which it is used. Eg. NOT EXISTS, NOT BETWEEN, NOT IN etc. This is
                negate operator.
OR              The OR operator is used to combine multiple conditions in an SQL
                statement's WHERE clause.
IS NULL         The NULL operator is used to retrieve NULL values
What is a Table?
Table – A set of data arranged in columns and rows. The columns represent
characteristics of stored data and the rows represent actual data entries.

In the below table called “employee_table” we see that the columns are:
First_Name, Last_Name, Email, DOB and Phone and rows are the data.

employee_table

First_Name   Last_Name   Email                   DOB            Phone
John         Smith       John.Smith@yahoo.com 2/4/1968          222 222-2222
Steven       Goldfish    goldfish@gmail.com      4/4/1974       999 455-4545
Paula        Brown       pb@hotmail.com          5/24/1978      777 323-3232
James        Smith       jim@ymail.com           20/10/1980     666 323-8888
Select Statement
  First_Name   Last_Name    Email                   DOB          Phone
  John         Smith        John.Smith@yahoo.com 2/4/1968        222 222-2222
  Steven       Goldfish     goldfish@gmail.com      4/4/1974     999 455-4545
  Paula        Brown        pb@hotmail.com          5/24/1978    777 323-3232
  James        Smith        jim@ymail.com           20/10/1980   666 323-8888


 Select * from employee_table
- All the columns in the employee_table are retrieved.


 Select First_Name, Last_Name from employee_table
- Only First_Name and Last_Name columns in the employee_table are retrieved.
Distinct Statement
 First_Name    Last_Name   Email                DOB          Phone
 John          Smith       John.Smith@yahoo.com 2/4/1968     222 222-2222
 Steven        Goldfish    goldfish@gmail.com   4/4/1974     999 455-4545
 Paula         Brown       pb@hotmail.com       5/24/1978    777 323-3232
 James         Smith       jim@ymail.com        20/10/1980   666 323-8888


 Select Distinct Last_Name from employee_table
    LastName
    Smith
    Goldfish
    Brown
Where Statement
 First_Name   Last_Name   Email                 DOB          Phone
 John         Smith       John.Smith@yahoo.com 2/4/1968      777 222-2222
 Steven       Goldfish    goldfish@gmail.com    4/4/1974     999 455-4545
 Paula        Brown       pb@hotmail.com        5/24/1978    777 323-8888
 James        Smith       jim@ymail.com         20/10/1980   666 323-8888


 Select * from employee_table
  where Last_Name= “Smith”
                          John.Smith@yahoo.co
 John         Smith                             2/4/1968     222 222-2222
                          m
 James        Smith       jim@ymail.com         20/10/1980   666 323-8888
Where Statement Examples:
<>, >, >=, <, =<, Like, Wildcard and Between
  SELECT *                     SELECT *
  FROM employee_table          FROM employee_table
  WHERE Last_Name <> 'Smith'   WHERE DOB =< ‘20/10/1980'
  SELECT *                     SELECT *
  FROM employee_table          FROM employee_table
  WHERE DOB > ‘20/10/1980'     WHERE Phone LIKE ’777%’

  SELECT *                     SELECT *
  FROM employee_table          FROM employee_table
  WHERE DOB >= ‘20/10/1980'    WHERE DOB BETWEEN ‘20/10/1980' AND
                               ‘20/10/1990'
  SELECT *
  FROM employee_table
  WHERE DOB < ‘20/10/1980'
Update Statement
First_Name       Last_Name   Email                    DOB            Phone
John             Smith       John.Smith@yahoo.com 2/4/1968           222 222-2222
Steven           Goldfish    goldfish@gmail.com       4/4/1974       999 455-4545
Paula            Brown       pb@hotmail.com           5/24/1978      777 323-3232
James            Smith       jim@ymail.com            20/10/1980     666 323-8888


                 UPDATE employee_table
                  SET DOB = '5/10/1974'
                  WHERE Last_Name = 'Goldfish' AND First_Name = 'Steven’

                 UPDATE employee_table
                  SET Phone = '626 555-5555'
                  WHERE Last_Name = 'Smith'
Delete Statement
First_Name    Last_Name   Email                DOB          Phone
John          Smith       John.Smith@yahoo.com 2/4/1968     222 222-2222
Steven        Goldfish    goldfish@gmail.com   4/4/1974     999 455-4545
Paula         Brown       pb@hotmail.com       5/24/1978    777 323-3232
James         Smith       jim@ymail.com        20/10/1980   666 323-8888


            DELETE FROM employee_table

            DELETE FROM employee_table
             WHERE Last_Name = 'Smith'
IN Statement




 SELECT * FROM Employee_Hours
  WHERE Date IN ('5/6/2004', '5/7/2004')

 SELECT * FROM Employee_Hours
  WHERE Hours IN (‘9’, ’10’)
Not IN Statement




 SELECT * FROM Employee_Hours
  WHERE Date NOT IN ('5/6/2004', '5/7/2004')

 SELECT * FROM Employee_Hours
  WHERE Hours NOT IN (‘9’, ’10’)
AND/ OR Operator
First_Name     Last_Name     Email                    DOB            Phone
John           Smith         John.Smith@yahoo.com 2/4/1968           222 222-2222
Steven         Goldfish      goldfish@gmail.com       4/4/1974       999 455-4545
Paula          Brown         pb@hotmail.com           5/24/1978      777 323-3232
James          Smith         jim@ymail.com            20/10/1980     666 323-8888



          SELECT * FROM Employee_table
           WHERE First_Name = ‘’John ’’ and Last_Name = ‘’ Smith’’

          SELECT * FROM Employee_table
           WHERE First_Name= ‘’Paula’’ or First_Name= ‘’James’’
TOP Statement
First_Name    Last_Name    Email                  DOB          Phone
John          Smith        John.Smith@yahoo.com 2/4/1968       222 222-2222
Steven        Goldfish     goldfish@gmail.com     4/4/1974     999 455-4545
Paula         Brown        pb@hotmail.com         5/24/1978    777 323-3232
James         Smith        jim@ymail.com          20/10/1980   666 323-8888



          SELECT TOP 10 * FROM Employee_table

          SELECT TOP 200 * FROM Employee_table
Insert Into Statement
  INSERT INTO employee_table (FirstName, LastName, Email, DOB, Phone)
   VALUES ('Peter', 'Hunt', 'peter.hunt@gmail.com', '1/1/1974', '626 888-8888’)

First_Name   Last_Name      Email                     DOB             Phone
John         Smith          John.Smith@yahoo.com 2/4/1968             222 222-2222
Steven       Goldfish       goldfish@gmail.com        4/4/1974        999 455-4545
Paula        Brown          pb@hotmail.com            5/24/1978       777 323-3232
James        Smith          jim@ymail.com             20/10/1980      666 323-8888
Peter        Hunt           Peter.hunt@gmail.com      1/1/1974        626 888-8888

  INSERT INTO employee_table
   VALUES ('Peter', 'Hunt', 'peter.hunt@gmail.com', '1/1/1974', '626 888-8888')
  INSERT INTO employee_table (FirstName, LastName)
   VALUES ('Peter', 'Hunt')
Select Into Statement
  SELECT FirstName, LastName
   INTO employee_table_name_backup
   FROM employee_table

First_Name   Last_Name   Email                  DOB          Phone
John         Smith       John.Smith@yahoo.com 2/4/1968       222 222-2222
Steven       Goldfish    goldfish@gmail.com     4/4/1974     999 455-4545
Paula        Brown       pb@hotmail.com         5/24/1978    777 323-3232
James        Smith       jim@ymail.com          20/10/1980   666 323-8888
Peter        Hunt        Peter.hunt@gmail.com   1/1/1974     626 888-8888
  SELECT *
   INTO employee_table_copy
   FROM employee_table
Count Statement
First_Name   Last_Name   Email                  DOB          Phone
John         Smith       John.Smith@yahoo.com 2/4/1968       222 222-2222
Steven       Goldfish    goldfish@gmail.com     4/4/1974     999 455-4545
Paula        Brown       pb@hotmail.com         5/24/1978    777 323-3232
James        Smith       jim@ymail.com          20/10/1980   666 323-8888
Peter        Hunt        Peter.hunt@gmail.com   1/1/1974     626 888-8888


  SELECT COUNT(*)
   FROM employee_table

  SELECT COUNT (First_Name)
   FROM employee_table
As Statement
First_Name   Last_Name   Email                  DOB          Phone
John         Smith       John.Smith@yahoo.com 2/4/1968       222 222-2222
Steven       Goldfish    goldfish@gmail.com     4/4/1974     999 455-4545
Paula        Brown       pb@hotmail.com         5/24/1978    777 323-3232
James        Smith       jim@ymail.com          20/10/1980   666 323-8888
Peter        Hunt        Peter.hunt@gmail.com   1/1/1974     626 888-8888


  SELECT Last_Name AS “EMP_LNAME”, Phone AS “Emergency_Contact”
   FROM employee_table

  SELECT COUNT (First_Name) AS “Number_of_employees”
   FROM employee_table
Order By Statement
First_Name   Last_Name   Email                  DOB          Phone
John         Smith       John.Smith@yahoo.com 2/4/1968       222 222-2222
Steven       Goldfish    goldfish@gmail.com     4/4/1974     999 455-4545
Paula        Brown       pb@hotmail.com         5/24/1978    777 323-3232
James        Smith       jim@ymail.com          20/10/1980   666 323-8888
Peter        Hunt        peter.hunt@gmail.com   1/1/1974     626 888-8888

  SELECT * FROM employee_table
   ORDER BY DOB
  SELECT * FROM employee_table
   ORDER BY DOB DESC
  SELECT * FROM employee_table
   ORDER BY DOB ASC
  SELECT * FROM employee_table
   ORDER BY DOB, Last_Name
MAX Function




 SELECT MAX(SaleAmount) As MAX_Sales
  FROM Sales
MIN Function




 SELECT Min(SaleAmount) As MIN_Sales
  FROM Sales
AVG Function




 SELECT AVG(SaleAmount) As AVG_Sales
  FROM Sales
SUM Function




 SELECT SUM(SaleAmount) As Total_Sales
  FROM Sales
Group By Statement




 Select Employee, SUM(Hours) As Total_Hours
  from Time_Table
  Group By Employee
Having Statement




 Select Employee, SUM(Hours) As Total_Hours
  from Time_Table
  Group By Employee
  Having SUM(Hours) >24
SQL Alias
CustomerID   First_Name   Email                  DOB          Phone
1            Smith        John.Smith@yahoo.com 2/4/1968       222 222-2222
2            Goldfish     goldfish@gmail.com     4/4/1974     999 455-4545
3            Brown        pb@hotmail.com         5/24/1978    777 323-3232
4            Kapil        jim@ymail.com          20/10/1980   666 323-8888
5            Hunt         Peter.hunt@gmail.com   1/1/1974     626 888-8888
SQL Alias (Contd.)

 Select a.First_Name, b.SaleAmount
  From Customer a, Sales b
  Where a.CustomerID=b.CustomerID

 Select a.Email, a.DOB, a.Phone, b.Date, b.SaleAmount
  From Customer a, Sales b
  Where a.CustomerID=b.CustomerID

 Select a.First_Name, SUM(b.SaleAmount) AS TOTALSALES
  From Customer a, Sales b
  Where a.CustomerID=b.CustomerID
  Group By a.First_Name
SQL Constraints

   NOT NULL
   UNIQUE
   PRIMARY KEY
   FOREIGN KEY
   CHECK
   DEFAULT
PK & UK Differences
Primary Key:
1. It will not accept null values.
2. There will be only one primary key in a
table.
3. Clustered index is created in Primary key.
4. Primary key allows each
row in a table to be uniquely identified and ensures that no duplicate rows
exist.

Unique Key:
1. Null values are accepted.
2. More than one unique key will
be there in a table.
3. Non-Clustered index is created in unique key.
4. Unique
key constraint is used to prevent the duplication of key values within the rows of
a table and allow null values.
INNER JOIN
Table A   Table B
FULL OUTER JOIN
Table A   Table B
FULL OUTER JOIN - Case
Table A    Table B
LEFT OUTER JOIN
Table A   Table B
LEFT OUTER JOIN - Case
Table A    Table B
CROSS JOIN/ Cartesian Product
Table A   Table B

Más contenido relacionado

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 Scriptwesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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 DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

SQL Course - QA

  • 2. What is SQL?  SQL stands for Structured Query Language  SQL lets you access and manipulate databases  SQL is an ANSI Standard ANSI: American National Standards Institute
  • 3. Why we use SQL?  SQL can execute queries against a database  SQL can retrieve data from a database  SQL can insert records in a database  SQL can update records in a database  SQL can delete records from a database  SQL can create new databases  SQL can create new tables in a database  SQL can create stored procedures in a database  SQL can create views in a database  SQL can set permissions on tables, procedures, and views
  • 4. What is RDBMS? RDBMS: Relational Database Management System *Software that stores and manipulates data arranged in relational database tables. Common RDBMS that use SQL are:  Oracle  Sybase  Microsoft SQL Server  Access
  • 5. DDL Data Definition Language (DDL) statements are used to define the database structure or schema.  CREATE - To create objects in the database  ALTER - Alters the structure of the database  DROP - Delete objects from the database  TRUNCATE - Remove all records from a table, including all spaces allocated for the records are removed
  • 6. DML Data Manipulation Language (DML) statements are used for managing data within schema objects.  SELECT - retrieve data from the a database  INSERT - insert data into a table  UPDATE - updates existing data within a table  DELETE - deletes all records from a table, the space for the records remain
  • 7. SQL Arithmetic Operators Operator Description Example + Addition - Adds values on either side a+b of the operator - Subtraction - Subtracts right hand a–b operand from left hand operand * Multiplication - Multiplies values on a*b either side of the operator / Division - Divides left hand operand by b / a right hand operand % Modulus - Divides left hand operand b%a by right hand operand and returns remainder
  • 8. SQL Comparison Operators Operator Description Example = Checks if the value of two operands are equal or not, if yes then (a = b) is not true. condition becomes true. != Checks if the value of two operands are equal or not, if values are not (a != b) is true. equal then condition becomes true. <> Checks if the value of two operands are equal or not, if values are not (a <> b) is true. equal then condition becomes true. > Checks if the value of left operand is greater than the value of right (a > b) is not true. operand, if yes then condition becomes true. < Checks if the value of left operand is less than the value of right (a < b) is true. operand, if yes then condition becomes true. >= Checks if the value of left operand is greater than or equal to the value (a >= b) is not true. of right operand, if yes then condition becomes true. <= Checks if the value of left operand is less than or equal to the value of (a <= b) is true. right operand, if yes then condition becomes true. !< Checks if the value of left operand is not less than the value of right (a !< b) is false. operand, if yes then condition becomes true. !> Checks if the value of left operand is not greater than the value of right (a !> b) is true. operand, if yes then condition becomes true.
  • 9. SQL Logical Operators Operator Description AND The AND operator allows the existence of multiple conditions in an SQL statement's WHERE clause. BETWEEN The BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value. IN The IN operator is used to compare a value to a list of literal values that have been specified. LIKE The LIKE operator is used to compare a value to similar values using wildcard operators. NOT The NOT operator reverses the meaning of the logical operator with which it is used. Eg. NOT EXISTS, NOT BETWEEN, NOT IN etc. This is negate operator. OR The OR operator is used to combine multiple conditions in an SQL statement's WHERE clause. IS NULL The NULL operator is used to retrieve NULL values
  • 10. What is a Table? Table – A set of data arranged in columns and rows. The columns represent characteristics of stored data and the rows represent actual data entries. In the below table called “employee_table” we see that the columns are: First_Name, Last_Name, Email, DOB and Phone and rows are the data. employee_table First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888
  • 11. Select Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888  Select * from employee_table - All the columns in the employee_table are retrieved.  Select First_Name, Last_Name from employee_table - Only First_Name and Last_Name columns in the employee_table are retrieved.
  • 12. Distinct Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888  Select Distinct Last_Name from employee_table LastName Smith Goldfish Brown
  • 13. Where Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 777 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-8888 James Smith jim@ymail.com 20/10/1980 666 323-8888  Select * from employee_table where Last_Name= “Smith” John.Smith@yahoo.co John Smith 2/4/1968 222 222-2222 m James Smith jim@ymail.com 20/10/1980 666 323-8888
  • 14. Where Statement Examples: <>, >, >=, <, =<, Like, Wildcard and Between SELECT * SELECT * FROM employee_table FROM employee_table WHERE Last_Name <> 'Smith' WHERE DOB =< ‘20/10/1980' SELECT * SELECT * FROM employee_table FROM employee_table WHERE DOB > ‘20/10/1980' WHERE Phone LIKE ’777%’ SELECT * SELECT * FROM employee_table FROM employee_table WHERE DOB >= ‘20/10/1980' WHERE DOB BETWEEN ‘20/10/1980' AND ‘20/10/1990' SELECT * FROM employee_table WHERE DOB < ‘20/10/1980'
  • 15. Update Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888  UPDATE employee_table SET DOB = '5/10/1974' WHERE Last_Name = 'Goldfish' AND First_Name = 'Steven’  UPDATE employee_table SET Phone = '626 555-5555' WHERE Last_Name = 'Smith'
  • 16. Delete Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888  DELETE FROM employee_table  DELETE FROM employee_table WHERE Last_Name = 'Smith'
  • 17. IN Statement  SELECT * FROM Employee_Hours WHERE Date IN ('5/6/2004', '5/7/2004')  SELECT * FROM Employee_Hours WHERE Hours IN (‘9’, ’10’)
  • 18. Not IN Statement  SELECT * FROM Employee_Hours WHERE Date NOT IN ('5/6/2004', '5/7/2004')  SELECT * FROM Employee_Hours WHERE Hours NOT IN (‘9’, ’10’)
  • 19. AND/ OR Operator First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888  SELECT * FROM Employee_table WHERE First_Name = ‘’John ’’ and Last_Name = ‘’ Smith’’  SELECT * FROM Employee_table WHERE First_Name= ‘’Paula’’ or First_Name= ‘’James’’
  • 20. TOP Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888  SELECT TOP 10 * FROM Employee_table  SELECT TOP 200 * FROM Employee_table
  • 21. Insert Into Statement  INSERT INTO employee_table (FirstName, LastName, Email, DOB, Phone) VALUES ('Peter', 'Hunt', 'peter.hunt@gmail.com', '1/1/1974', '626 888-8888’) First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888 Peter Hunt Peter.hunt@gmail.com 1/1/1974 626 888-8888  INSERT INTO employee_table VALUES ('Peter', 'Hunt', 'peter.hunt@gmail.com', '1/1/1974', '626 888-8888')  INSERT INTO employee_table (FirstName, LastName) VALUES ('Peter', 'Hunt')
  • 22. Select Into Statement  SELECT FirstName, LastName INTO employee_table_name_backup FROM employee_table First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888 Peter Hunt Peter.hunt@gmail.com 1/1/1974 626 888-8888  SELECT * INTO employee_table_copy FROM employee_table
  • 23. Count Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888 Peter Hunt Peter.hunt@gmail.com 1/1/1974 626 888-8888  SELECT COUNT(*) FROM employee_table  SELECT COUNT (First_Name) FROM employee_table
  • 24. As Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888 Peter Hunt Peter.hunt@gmail.com 1/1/1974 626 888-8888  SELECT Last_Name AS “EMP_LNAME”, Phone AS “Emergency_Contact” FROM employee_table  SELECT COUNT (First_Name) AS “Number_of_employees” FROM employee_table
  • 25. Order By Statement First_Name Last_Name Email DOB Phone John Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 Steven Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 Paula Brown pb@hotmail.com 5/24/1978 777 323-3232 James Smith jim@ymail.com 20/10/1980 666 323-8888 Peter Hunt peter.hunt@gmail.com 1/1/1974 626 888-8888  SELECT * FROM employee_table ORDER BY DOB  SELECT * FROM employee_table ORDER BY DOB DESC  SELECT * FROM employee_table ORDER BY DOB ASC  SELECT * FROM employee_table ORDER BY DOB, Last_Name
  • 26. MAX Function  SELECT MAX(SaleAmount) As MAX_Sales FROM Sales
  • 27. MIN Function  SELECT Min(SaleAmount) As MIN_Sales FROM Sales
  • 28. AVG Function  SELECT AVG(SaleAmount) As AVG_Sales FROM Sales
  • 29. SUM Function  SELECT SUM(SaleAmount) As Total_Sales FROM Sales
  • 30. Group By Statement  Select Employee, SUM(Hours) As Total_Hours from Time_Table Group By Employee
  • 31. Having Statement  Select Employee, SUM(Hours) As Total_Hours from Time_Table Group By Employee Having SUM(Hours) >24
  • 32. SQL Alias CustomerID First_Name Email DOB Phone 1 Smith John.Smith@yahoo.com 2/4/1968 222 222-2222 2 Goldfish goldfish@gmail.com 4/4/1974 999 455-4545 3 Brown pb@hotmail.com 5/24/1978 777 323-3232 4 Kapil jim@ymail.com 20/10/1980 666 323-8888 5 Hunt Peter.hunt@gmail.com 1/1/1974 626 888-8888
  • 33. SQL Alias (Contd.)  Select a.First_Name, b.SaleAmount From Customer a, Sales b Where a.CustomerID=b.CustomerID  Select a.Email, a.DOB, a.Phone, b.Date, b.SaleAmount From Customer a, Sales b Where a.CustomerID=b.CustomerID  Select a.First_Name, SUM(b.SaleAmount) AS TOTALSALES From Customer a, Sales b Where a.CustomerID=b.CustomerID Group By a.First_Name
  • 34. SQL Constraints  NOT NULL  UNIQUE  PRIMARY KEY  FOREIGN KEY  CHECK  DEFAULT
  • 35. PK & UK Differences Primary Key: 1. It will not accept null values.
2. There will be only one primary key in a table.
3. Clustered index is created in Primary key.
4. Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist. Unique Key:
1. Null values are accepted.
2. More than one unique key will be there in a table.
3. Non-Clustered index is created in unique key.
4. Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.
  • 38. FULL OUTER JOIN - Case Table A Table B
  • 40. LEFT OUTER JOIN - Case Table A Table B
  • 41. CROSS JOIN/ Cartesian Product Table A Table B