SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
Adding data to a table -The INSERT statement




Can also be used to add a row to a view
Syntax:
      INSERT INTO <tablename>
      (column1,column2.,..)
      VALUES(<value1>,<value2>.,..);
                                          MG/DB CONCEPTS/CL12
Data can be added only to some columns in a row
by specifying the columns and their data.


Example:
INSERT INTO Employee (ecode, name, dept)
    VALUES (2001, 'Rani', 'Accounts');


The columns that are not listed in the INSERT
command will have their default value, if it is
defined otherwise NULL value.            MG/DB CONCEPTS/CL12
MG/DB CONCEPTS/CL12
Example:

INSERT INTO Employee VALUES (1001,
'Ram', 'Admin', 'Typist', ‘10-MAR-04’);


  The insert statement adds a new row to
Employee giving a value for every column in the
row.
  The data values must be in the same order as the
column names in the table.

                                       MG/DB CONCEPTS/CL12
View data in the table - The Select statement




                                    MG/DB CONCEPTS/CL12
The select command displays information
from the table as a set of records.
Syntax:
SELECT [DISTINCT/ALL] {* FROM
<table name>[,<table name>]}
 [WHERE clause][GROUP BY clause]
[HAVING clause] [ORDER BY clause] ;


                                MG/DB CONCEPTS/CL12
Three keywords make up a basic select statement:
SELECT, FROM AND WHERE.
  The SELECT statement retrieves rows from the
table.
  The FROM clause specifies the table where the
columns are located.
 The WHERE clause specifies the rows.
  Examples:
  SELECT * FROM Employee;
  SELECT empno, name FROM Employee;
                                     MG/DB CONCEPTS/CL12
Reordering columns in query results
   In the select query, the column names can be
specified in any order.
  The output will be in exactly the same order.
   The order of selection determines the order of
display.
Example:
SELECT Dept, Job_title, Empno, Name FROM
Employee;
                                        MG/DB CONCEPTS/CL12
Selecting data from all the rows using the
keyword ALL
The keyword ALL retains duplicate rows from
the results of a SELECT statement.
Example:
SELECT ALL Name FROM Employee;


The above statement outputs values of the
column name from every row of the table.
                                  MG/DB CONCEPTS/CL12
Eliminating redundant data using the keyword
 DISTINCT
   The distinct keyword eliminates duplicate rows from
the results of a SELECT statement.
Example:
SELECT DISTINCT Name FROM Employee;
In this example, the output will not have duplicate rows.
   The DISTINCT keyword can be specified only once in
a given SELECT clause.
   If the clause selects multiple fields, DISTINCT
eliminates rows, where all of the selected fields are
identical.                                   MG/DB CONCEPTS/CL12
Changing column headings
   By default, the column heading displayed in the query
results is the column name designated when the table was
created.
   However, it is possible to change the column heading
by including it in the select_list.
   Changing column heading is referred to as aliasing;
this is done to make the results more readable.
Example:
SELECT empno as emp_number, name as emp_name,
doj as date_of_joining from employee;
                                           MG/DB CONCEPTS/CL12
MG/DB CONCEPTS/CL12
MG/DB CONCEPTS/CL12
Selecting specific rows – WHERE clause in
SELECT


The WHERE clause in SELECT statement
specifies the search criteria for selecting rows.


Syntax:
SELECT <column name>[,<column name>]
FROM <table name> WHERE <condition>;
                                      MG/DB CONCEPTS/CL12
The condition statement known as the search criteria, in
the WHERE clause can include the following:


Comparison operators     <, >, <=, >=, !<, !>, <>, =
Ranges                   BETWEEN and NOT BETWEEN
Lists                    IN and NOT IN
String matches           LIKE and NOT LIKE
Unknown values           IS NULL and IS NOT NULL
Logical operators        AND, OR
Negation                 NOT


                                                MG/DB CONCEPTS/CL12
Choosing rows based on comparisons
  Comparison operators allow you to select rows by
comparing a row to a given value or expression.
   Used optionally in SELECT, UPDATE, and DELETE
commands to restrict their operations to the rows
specified.
SELECT select_list FROM table_list
WHERE [NOT] <search condition>
[AND/OR [NOT] <search condition>...]
Searches for rows WHERE the comparison between the
specified expressions is true.
                                        MG/DB CONCEPTS/CL12
The valid SQL comparison symbols are:
< Less than        <= Less than or equal
> Greater than     >= Greater than or equal
!< Not less than   !> Not greater than
= Equal            <> or != or # Not equal


Example:
SELECT name FROM Employee WHERE salary >= 50000;



                                              MG/DB CONCEPTS/CL12
WHERE – AND and OR to link conditions
Logical operators can be used to connect search
conditions in a WHERE clause.
SELECT select_list FROM table_list
WHERE <search condition> AND/OR       <search_condition>...]

  If conditions are linked by AND, the WHERE clause is
true only if both search conditions are evaluated as true.
  If conditions are linked by OR, the WHERE clause is
true if either search condition is evaluated to be true.
Example:
SELECT * FROM Employee WHERE dept = 'Admin'
OR dept = 'Accounts’                        MG/DB CONCEPTS/CL12
WHERE – NOT to reverse condition
NOT can be used to reverse the meaning of an entire WHERE search
condition.
SELECT select_list FROM table_list
WHERE NOT <search condition>
Example:
SELECT name FROM Employee WHERE NOT salary >= 50000;
Note:
NOT also an option within certain conditions, where it reverses the
meaning of the keyword
NOT <Comparison conditions> ,        NOT BETWEEN,
NOT LIKE,       NOT IN,       NOT EXISTS
                                                   MG/DB CONCEPTS/CL12
Choosing rows based on a range(WHERE – BETWEEN)
  The BETWEEN operator can be used to search for a range of
      values in a WHERE clause.
  The range includes both the lower value and the upper value.
       SELECT select_list FROM table_list WHERE [NOT]
       <expression> [NOT] BETWEEN <expression1> AND
       <expression2>
  Searches for rows WHERE the specified expression's value falls
BETWEEN the two expressions.
  BETWEEN is equivalent to <expression> >= <expression1> and
<expression> <= <expression2>
Example:
SELECT name from Employee WHERE salary BETWEEN
     15000 AND 25000;                              MG/DB CONCEPTS/CL12
Choosing rows based on a list(WHERE – IN)
  To specify a list of values, IN keyword is used.
    The IN operator selects values that match any value in a given
list of values.
SELECT select_list FROM table_list WHERE [NOT]
     <expression> [NOT] IN (<valuelist>/<subselect>)
 Searches for all rows WHERE the specified column's value
matches any of the values.
   These values may be a simple list, or they may be returned by
a subselect.
Example:
SELECT name FROM Employee WHERE dept IN ('Software',
'Admin', 'Sales');
                                                     MG/DB CONCEPTS/CL12
Choosing rows based on character strings (WHERE – LIKE)
 SQL includes a string matching operator, LIKE for comparisons on
character strings using patterns. Patterns are described using
wildcard characters.




                                                   MG/DB CONCEPTS/CL12
Wildcard     Description
%          Any string of zero or more characters
_          (underscore) Any single character


Syntax: SELECT select_list FROM table_list
WHERE [NOT] <column name> [NOT] LIKE
'<search string>'
Searches for rows WHERE the specified column's
value matches the search string.


                                               MG/DB CONCEPTS/CL12
The following example searches for all names beginning with A
Ex:   SELECT * FROM Employee WHERE name LIKE 'A%';


NOTE:
  A string with wildcard characters must always be enclosed in
quotation marks.
 Patterns are case sensitive, i.e, upper case characters do not
match lower case characters or vice versa




                                                  MG/DB CONCEPTS/CL12
Examples of using wildcards with the LIKE clause:
Expression        returns
LIKE ‘A%’         Every name that begins with A
                  followed by any number of characters
LIKE ‘Ar__’       Every name that begins with Ar
                  followed by 2 more characters
LIKE ‘%ter’       Every name that ends with ter
LIKE ‘%ar%’       Every name that has letters ar in it
LIKE ‘_om’        Every three-letter name ending with om


                                              MG/DB CONCEPTS/CL12
Choosing rows based on unknown values(Searching for
NULL)
NULL means that the value for that column is unknown or
unavailable. To select rows with NULL values, use IS
NULL in the WHERE clause.
Syntax:
      SELECT select_list FROM table_list
      WHERE column_name IS [NOT] NULL
Ex: SELECT * FROM Employee WHERE desig IS
NULL;
Non Null values in a table can be listed by using IS NOT
NULL                                       MG/DB CONCEPTS/CL12
SELECT INTO
A SELECT statement with an INTO clause allows you
to define a table and put data into it without going
through the usual data definition process.
  SELECT INTO creates a new table based in the
results of a query.
   If a table already exists with the same name, this
statement will fail.
  The new table columns and rows are based the
select_list specifies in the query.

                                          MG/DB CONCEPTS/CL12
Syntax:
     SELECT select_list
     INTO new_table_name
     FROM table_name
     WHERE search_conditon
Examples:
SELECT empcode, name INTO temp1 FROM emp;

SELECT empno, name INTO temp2 FROM EMP
WHERE job_title="Manager";
                                   MG/DB CONCEPTS/CL12
Sorting results – ORDER BY clause
  ORDER BY sorts query results by one or more columns.
  ORDER BY clause is the last clause in a SQL statement. It can
operate on multiple fields.
 Syntax:
SELECT select_list FROM table_list
ORDER BY <column name>/<integer> [ASC/DESC] [,<column
name>/<integer> [ASC/DESC]...];
  ORDERs the displayed rows by the values in the specified
column(s).
 ASC or DESC specifies whether values will be displayed in
ASCending or DESCending order.
 ASC is the default. You cannot ORDER BY columns of type
LOGICAL
                                                MG/DB CONCEPTS/CL12
The following example arranges rows by dept; within
each dept, rows are arranged by salary


SELECT empno, name, dept, salary FROM EMP
ORDER BY dept, salary desc;


NOTE: ORDER BY cannot be used inside a nested
SUB-SELECT.




                                         MG/DB CONCEPTS/CL12

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
MY SQL
MY SQLMY SQL
MY SQL
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Sql select
Sql select Sql select
Sql select
 
SQL
SQLSQL
SQL
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and Privileges
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
SQL
SQLSQL
SQL
 
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
 
Sql server select queries ppt 18
Sql server select queries ppt 18Sql server select queries ppt 18
Sql server select queries ppt 18
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 
1 introduction to my sql
1 introduction to my sql1 introduction to my sql
1 introduction to my sql
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 

Destacado

Il Mercato Digitale
Il Mercato DigitaleIl Mercato Digitale
Il Mercato DigitaleHibo
 
Hugo Kołłątaj
Hugo KołłątajHugo Kołłątaj
Hugo Kołłątajguest697ddc
 
Valinnainen Tietotekniikka Syksy 2009
Valinnainen Tietotekniikka Syksy 2009Valinnainen Tietotekniikka Syksy 2009
Valinnainen Tietotekniikka Syksy 2009Freezeant
 
Netiketti
NetikettiNetiketti
NetikettiPete15
 

Destacado (7)

Art
ArtArt
Art
 
Il Mercato Digitale
Il Mercato DigitaleIl Mercato Digitale
Il Mercato Digitale
 
Hugo Kołłątaj
Hugo KołłątajHugo Kołłątaj
Hugo Kołłątaj
 
Advitronics
AdvitronicsAdvitronics
Advitronics
 
Valinnainen Tietotekniikka Syksy 2009
Valinnainen Tietotekniikka Syksy 2009Valinnainen Tietotekniikka Syksy 2009
Valinnainen Tietotekniikka Syksy 2009
 
Netiketti
NetikettiNetiketti
Netiketti
 
Nelida_Nunez 2015 (1)
Nelida_Nunez 2015 (1)Nelida_Nunez 2015 (1)
Nelida_Nunez 2015 (1)
 

Similar a Sql2

Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Vidyasagar Mundroy
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankpptnewrforce
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptxEllenGracePorras
 
Sql select statement
Sql select statementSql select statement
Sql select statementVivek Singh
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxjainendraKUMAR55
 
Module 3.1.pptx
Module 3.1.pptxModule 3.1.pptx
Module 3.1.pptxANSHVAJPAI
 
Sql order by clause
Sql order by clauseSql order by clause
Sql order by clauseVivek Singh
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIMsKanchanaI
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQueryAbhishek590097
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Achmad Solichin
 

Similar a Sql2 (20)

0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
Query
QueryQuery
Query
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Sql select statement
Sql select statementSql select statement
Sql select statement
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
Module 3.1.pptx
Module 3.1.pptxModule 3.1.pptx
Module 3.1.pptx
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
Updat Dir
Updat DirUpdat Dir
Updat Dir
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
Sql order by clause
Sql order by clauseSql order by clause
Sql order by clause
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Module03
Module03Module03
Module03
 
Les06
Les06Les06
Les06
 
Les02
Les02Les02
Les02
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 

Último

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 TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
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 FMESafe Software
 
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 Takeoffsammart93
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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 Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 MilvusZilliz
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Último (20)

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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
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
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Sql2

  • 1. Adding data to a table -The INSERT statement Can also be used to add a row to a view Syntax: INSERT INTO <tablename> (column1,column2.,..) VALUES(<value1>,<value2>.,..); MG/DB CONCEPTS/CL12
  • 2. Data can be added only to some columns in a row by specifying the columns and their data. Example: INSERT INTO Employee (ecode, name, dept) VALUES (2001, 'Rani', 'Accounts'); The columns that are not listed in the INSERT command will have their default value, if it is defined otherwise NULL value. MG/DB CONCEPTS/CL12
  • 4. Example: INSERT INTO Employee VALUES (1001, 'Ram', 'Admin', 'Typist', ‘10-MAR-04’); The insert statement adds a new row to Employee giving a value for every column in the row. The data values must be in the same order as the column names in the table. MG/DB CONCEPTS/CL12
  • 5. View data in the table - The Select statement MG/DB CONCEPTS/CL12
  • 6. The select command displays information from the table as a set of records. Syntax: SELECT [DISTINCT/ALL] {* FROM <table name>[,<table name>]} [WHERE clause][GROUP BY clause] [HAVING clause] [ORDER BY clause] ; MG/DB CONCEPTS/CL12
  • 7. Three keywords make up a basic select statement: SELECT, FROM AND WHERE. The SELECT statement retrieves rows from the table. The FROM clause specifies the table where the columns are located. The WHERE clause specifies the rows. Examples: SELECT * FROM Employee; SELECT empno, name FROM Employee; MG/DB CONCEPTS/CL12
  • 8. Reordering columns in query results In the select query, the column names can be specified in any order. The output will be in exactly the same order. The order of selection determines the order of display. Example: SELECT Dept, Job_title, Empno, Name FROM Employee; MG/DB CONCEPTS/CL12
  • 9. Selecting data from all the rows using the keyword ALL The keyword ALL retains duplicate rows from the results of a SELECT statement. Example: SELECT ALL Name FROM Employee; The above statement outputs values of the column name from every row of the table. MG/DB CONCEPTS/CL12
  • 10. Eliminating redundant data using the keyword DISTINCT The distinct keyword eliminates duplicate rows from the results of a SELECT statement. Example: SELECT DISTINCT Name FROM Employee; In this example, the output will not have duplicate rows. The DISTINCT keyword can be specified only once in a given SELECT clause. If the clause selects multiple fields, DISTINCT eliminates rows, where all of the selected fields are identical. MG/DB CONCEPTS/CL12
  • 11. Changing column headings By default, the column heading displayed in the query results is the column name designated when the table was created. However, it is possible to change the column heading by including it in the select_list. Changing column heading is referred to as aliasing; this is done to make the results more readable. Example: SELECT empno as emp_number, name as emp_name, doj as date_of_joining from employee; MG/DB CONCEPTS/CL12
  • 14. Selecting specific rows – WHERE clause in SELECT The WHERE clause in SELECT statement specifies the search criteria for selecting rows. Syntax: SELECT <column name>[,<column name>] FROM <table name> WHERE <condition>; MG/DB CONCEPTS/CL12
  • 15. The condition statement known as the search criteria, in the WHERE clause can include the following: Comparison operators <, >, <=, >=, !<, !>, <>, = Ranges BETWEEN and NOT BETWEEN Lists IN and NOT IN String matches LIKE and NOT LIKE Unknown values IS NULL and IS NOT NULL Logical operators AND, OR Negation NOT MG/DB CONCEPTS/CL12
  • 16. Choosing rows based on comparisons Comparison operators allow you to select rows by comparing a row to a given value or expression. Used optionally in SELECT, UPDATE, and DELETE commands to restrict their operations to the rows specified. SELECT select_list FROM table_list WHERE [NOT] <search condition> [AND/OR [NOT] <search condition>...] Searches for rows WHERE the comparison between the specified expressions is true. MG/DB CONCEPTS/CL12
  • 17. The valid SQL comparison symbols are: < Less than <= Less than or equal > Greater than >= Greater than or equal !< Not less than !> Not greater than = Equal <> or != or # Not equal Example: SELECT name FROM Employee WHERE salary >= 50000; MG/DB CONCEPTS/CL12
  • 18. WHERE – AND and OR to link conditions Logical operators can be used to connect search conditions in a WHERE clause. SELECT select_list FROM table_list WHERE <search condition> AND/OR <search_condition>...] If conditions are linked by AND, the WHERE clause is true only if both search conditions are evaluated as true. If conditions are linked by OR, the WHERE clause is true if either search condition is evaluated to be true. Example: SELECT * FROM Employee WHERE dept = 'Admin' OR dept = 'Accounts’ MG/DB CONCEPTS/CL12
  • 19. WHERE – NOT to reverse condition NOT can be used to reverse the meaning of an entire WHERE search condition. SELECT select_list FROM table_list WHERE NOT <search condition> Example: SELECT name FROM Employee WHERE NOT salary >= 50000; Note: NOT also an option within certain conditions, where it reverses the meaning of the keyword NOT <Comparison conditions> , NOT BETWEEN, NOT LIKE, NOT IN, NOT EXISTS MG/DB CONCEPTS/CL12
  • 20. Choosing rows based on a range(WHERE – BETWEEN) The BETWEEN operator can be used to search for a range of values in a WHERE clause. The range includes both the lower value and the upper value. SELECT select_list FROM table_list WHERE [NOT] <expression> [NOT] BETWEEN <expression1> AND <expression2> Searches for rows WHERE the specified expression's value falls BETWEEN the two expressions. BETWEEN is equivalent to <expression> >= <expression1> and <expression> <= <expression2> Example: SELECT name from Employee WHERE salary BETWEEN 15000 AND 25000; MG/DB CONCEPTS/CL12
  • 21. Choosing rows based on a list(WHERE – IN) To specify a list of values, IN keyword is used. The IN operator selects values that match any value in a given list of values. SELECT select_list FROM table_list WHERE [NOT] <expression> [NOT] IN (<valuelist>/<subselect>) Searches for all rows WHERE the specified column's value matches any of the values. These values may be a simple list, or they may be returned by a subselect. Example: SELECT name FROM Employee WHERE dept IN ('Software', 'Admin', 'Sales'); MG/DB CONCEPTS/CL12
  • 22. Choosing rows based on character strings (WHERE – LIKE) SQL includes a string matching operator, LIKE for comparisons on character strings using patterns. Patterns are described using wildcard characters. MG/DB CONCEPTS/CL12
  • 23. Wildcard Description % Any string of zero or more characters _ (underscore) Any single character Syntax: SELECT select_list FROM table_list WHERE [NOT] <column name> [NOT] LIKE '<search string>' Searches for rows WHERE the specified column's value matches the search string. MG/DB CONCEPTS/CL12
  • 24. The following example searches for all names beginning with A Ex: SELECT * FROM Employee WHERE name LIKE 'A%'; NOTE: A string with wildcard characters must always be enclosed in quotation marks. Patterns are case sensitive, i.e, upper case characters do not match lower case characters or vice versa MG/DB CONCEPTS/CL12
  • 25. Examples of using wildcards with the LIKE clause: Expression returns LIKE ‘A%’ Every name that begins with A followed by any number of characters LIKE ‘Ar__’ Every name that begins with Ar followed by 2 more characters LIKE ‘%ter’ Every name that ends with ter LIKE ‘%ar%’ Every name that has letters ar in it LIKE ‘_om’ Every three-letter name ending with om MG/DB CONCEPTS/CL12
  • 26. Choosing rows based on unknown values(Searching for NULL) NULL means that the value for that column is unknown or unavailable. To select rows with NULL values, use IS NULL in the WHERE clause. Syntax: SELECT select_list FROM table_list WHERE column_name IS [NOT] NULL Ex: SELECT * FROM Employee WHERE desig IS NULL; Non Null values in a table can be listed by using IS NOT NULL MG/DB CONCEPTS/CL12
  • 27. SELECT INTO A SELECT statement with an INTO clause allows you to define a table and put data into it without going through the usual data definition process. SELECT INTO creates a new table based in the results of a query. If a table already exists with the same name, this statement will fail. The new table columns and rows are based the select_list specifies in the query. MG/DB CONCEPTS/CL12
  • 28. Syntax: SELECT select_list INTO new_table_name FROM table_name WHERE search_conditon Examples: SELECT empcode, name INTO temp1 FROM emp; SELECT empno, name INTO temp2 FROM EMP WHERE job_title="Manager"; MG/DB CONCEPTS/CL12
  • 29. Sorting results – ORDER BY clause ORDER BY sorts query results by one or more columns. ORDER BY clause is the last clause in a SQL statement. It can operate on multiple fields. Syntax: SELECT select_list FROM table_list ORDER BY <column name>/<integer> [ASC/DESC] [,<column name>/<integer> [ASC/DESC]...]; ORDERs the displayed rows by the values in the specified column(s). ASC or DESC specifies whether values will be displayed in ASCending or DESCending order. ASC is the default. You cannot ORDER BY columns of type LOGICAL MG/DB CONCEPTS/CL12
  • 30. The following example arranges rows by dept; within each dept, rows are arranged by salary SELECT empno, name, dept, salary FROM EMP ORDER BY dept, salary desc; NOTE: ORDER BY cannot be used inside a nested SUB-SELECT. MG/DB CONCEPTS/CL12