SlideShare uma empresa Scribd logo
1 de 31
MagnaDataSolutions.com
Getting started with the
SQL Language
Cecilia Brusatori
Magna Data Inc
MagnaDataSolutions.com
Cecilia Brusatori
ready
Founder and CEO of Magna Data inc​
Data Analytics Solutions and Corporate Training
University Graduate Degree in Computer Science
& Engineering
Tech Community Leader & Organizer in South
Florida US
Proudly Nerd​ - Always Learning - Naturist –
Love Animals, good Books & the Beach
Entrepreneur - Consultant, Trainer, Speaker
Miami/Fort Lauderdale Area
MagnaDataSolutions.com
Agenda
 DBs Concepts & Terminology
 Intro to SQL Language
 DML Syntax: SELECT, UPDATE, INSERT, DELETE
 Exploring SELECT
 WHERE, Operators
 Aggregations
 Group By, Having
 Types of Joins
MagnaDataSolutions.com
Databases
Concepts & Terminology
MagnaDataSolutions.com
RDBMS
 Relational Database Management Systems
 Software that provides Users and
Applications, with processes to: Define,
Create, Manipulate and Share (Relational)
Databases
User Applications
RDBMS Server
…
MagnaDataSolutions.com
Relational Databases
 Database > Tables > Rows > Columns
1
1..*
1
1
0..*
1
0..*
0..*
 ERD: display entities
and how they are
related
 Primary Keys (PK):
Uniquely identifies
each record in a table
 Foreign Keys (FK):
refers to the Primary
Key in another table
MagnaDataSolutions.com
Introduction to SQL
MagnaDataSolutions.com
About the SQL Language
 Structured Query Language
 SQL / SEQUEL (Structured English Query Language)
 Interact with Relational Databases
 Comes from Relational Algebra & Calculus.
Codd, Chamberlin & Boyce.
SQL history by Chamberlin, here: https://ieeexplore.ieee.org/document/6359709
 Declarative Language vs Procedural/imperative language
 SQL Standard defined by ANSI (American National Standards Institute)
 Vendors variations and extensions.
MagnaDataSolutions.com
Extensions to SQL Language
Add Procedural Programming Language Functionality (Functions,
Cursors, arrays, loops, Control of Flows, etc)
Oracle PL/SQL Procedural Language/SQL
Microsoft SQL Server T-SQL Transact-SQL
Informix SPL Stored Procedural Language
MySQL SQL/PSM SQL/Persistent Stored Module
PostgreSQL PL/pgSQL Procedural Language/PostgreSQL SQL
SAP R3 ABAP Advance Business Application Programming
MariaDB SQL/PSM SQL/Persistent Stored Module
MagnaDataSolutions.com
Language Classifications
SQL
DDL
Create, Alter,
Drop, Rename
DML
Select, Insert,
Update, Delete
DCL
Grant,
Revoke, Deny
RDBMS Server
MagnaDataSolutions.com
DML SYNTAX
MagnaDataSolutions.com
DML - Syntax
SELECT Column1, Column2, … FROM Table1
SELECT Column1, Column2, … FROM Table1 WHERE Condition
INSERT INTO Table1 (Column1,Column2,…) VALUES(Value1,Value2,…)
UPDATE Table1 SET Column1=Value1, Column2=Value2,…
UPDATE Table1 SET Column1=Value1, Column2=Value2,… WHERE Condition
DELETE FROM Table1
DELETE FROM Table1 WHERE Condition
MagnaDataSolutions.com
DML – Syntax - Examples
• SELECT FirstName, LastName, email, DoB, FROM Customer;
• UPDATE Customer SET LastName=‘Smith’ WHERE CustomerID=123;
• INSERT INTO Customer(FirstName, LastName, email)
VALUES (‘Jane’, ’Doe’, ’Jdoe@gmail.com’);
• DELETE FROM Customer WHERE CustomerID = 123;
MagnaDataSolutions.com
Interaction Example
SQL Statement
SELECT * FROM [Orders]
User/App
Microsoft
SQL Server
1
2 3
4
MagnaDataSolutions.com
Let’s Explore SELECT
DML
MagnaDataSolutions.com
SELECT
 Selects Data and Returns a Result-set. (result table)
 * Brings all fields
 Specify Columns
SELECT * FROM Table1;
SELECT Column1, Column2, …, ColumnN FROM Table1;
MagnaDataSolutions.com
ORDER BY
 Sorts the Result_set by the Column(s) specified.
 ASC, DESC
SELECT Column1, Column2
FROM Table1
ORDER BY Column1 DESC;
MagnaDataSolutions.com
WHERE Clause
SELECT Column1, Column2
FROM Table1
WHERE Condition;
Conditionals:
 Boolean operators/Logical Operators AND, OR, NOT
 Comparison operators:
 =,<>,<=,>. Some DBs inequality: !=,^=,<>
 ANY/SOME
 EXISTS
 LIKE
 BETWEEN
 IS NULL
MagnaDataSolutions.com
NULL values
 Represents “Nothingness”. It is not a Value. It is an Empty field
 Origin: Value not entered/recorded
 May affect results (Example with AVG)
 Used with operators IS/NOT: IS NULL, IS NOT NULL
MagnaDataSolutions.com
Aggregations
Function Description
COUNT() Counts elements in a column. COUNT (*) counts tuples.
SUM() Returns the Summarization of all values in a column.
AVG() Returns the Average from values in a column.
MAX() Returns the Maximum value in a column.
MIN() Returns the Minimum value in a column
MagnaDataSolutions.com
GROUP BY
Create Subgroups of Tuples
SELECT Column1, SUM(Column2)
FROM Table1
GROUP BY Column1;
MagnaDataSolutions.com
HAVING
 HAVING clause: contains conditions on aggregates
 Specifies a search condition for Groups
SELECT Column1, SUM(Column2)
FROM Table1
GROUP BY Column1
HAVING SUM(Column2) >10000;
MagnaDataSolutions.com
Syntax Evaluation Order (Ms SQL Server)
1
2
3
4
5
6
MagnaDataSolutions.com
Types of JOINS
Natural Join,
INNER Join,
Join
Left Outer Join Right Outer Join
Full Outer Join
MagnaDataSolutions.com
Inner Join
SELECT *
FROM Table1 T1 INNER JOIN
Table2 T2 ON (T1.ID=T2.ID)
MagnaDataSolutions.com
Left Outer Join
SELECT *
FROM Table1 T1 LEFT JOIN
Table2 T2 ON (T1.ID=T2.ID)
MagnaDataSolutions.com
Right Outer Join
SELECT *
FROM Table1 T1 RIGHT JOIN
Table2 T2 ON (T1.ID=T2.ID)
MagnaDataSolutions.com
Full Outer Join
SELECT *
FROM Table1 T1 FULL OUTER JOIN
Table2 T2 ON (T1.ID=T2.ID)
MagnaDataSolutions.com
Oracle
SQL
MagnaDataSolutions.com
Resources
 Practice website:
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
 Oracle:
https://docs.oracle.com/en/database/oracle/oracle-
database/19/sqlrf/Introduction-to-Oracle-SQL.html
 PostgreSQL:
https://www.postgresql.org/docs/current/sql.html
 Ms SQL Server:
https://learn.microsoft.com/en-us/training/paths/get-started-querying-with-
transact-sql/
 MySQL:
https://dev.mysql.com/doc/refman/8.0/en/sql-statements.html
 IBM DB2:
https://www.ibm.com/docs/en/db2-for-zos/11?topic=db2-sql
MagnaDataSolutions.com
THANK YOU!
Connect to me at: Cecilia@MagnaDataSolutions.com
/CeBrusa
@CeBrusa
@MagnaDatainc
@MagnaDatainc
/company/magnadatainc
https://magnadatainc.com
Presentation:
www.MagnaDataSolutions.com/intro-to-sql-language

Mais conteúdo relacionado

Semelhante a Getting Started with SQL Language.pptx

Semelhante a Getting Started with SQL Language.pptx (20)

SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
Chapter 2: Ms SQL Server
Chapter 2: Ms SQL ServerChapter 2: Ms SQL Server
Chapter 2: Ms SQL Server
 
[PHPUGPH] PHP Roadshow - MySQL
[PHPUGPH] PHP Roadshow - MySQL[PHPUGPH] PHP Roadshow - MySQL
[PHPUGPH] PHP Roadshow - MySQL
 
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)
 
Module 02 teradata basics
Module 02 teradata basicsModule 02 teradata basics
Module 02 teradata basics
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Sql
SqlSql
Sql
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
lovely
lovelylovely
lovely
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
PO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - SqlPO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - Sql
 
Database programming
Database programmingDatabase programming
Database programming
 
SQL and Integrity Constraints (2).pptx
SQL and Integrity Constraints (2).pptxSQL and Integrity Constraints (2).pptx
SQL and Integrity Constraints (2).pptx
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
Presentation1
Presentation1Presentation1
Presentation1
 
Lecture05sql 110406195130-phpapp02
Lecture05sql 110406195130-phpapp02Lecture05sql 110406195130-phpapp02
Lecture05sql 110406195130-phpapp02
 
SQL Server 2008 for Developers
SQL Server 2008 for DevelopersSQL Server 2008 for Developers
SQL Server 2008 for Developers
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Lab
LabLab
Lab
 

Último

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 
[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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
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 WorkerThousandEyes
 

Último (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
[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
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
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
 

Getting Started with SQL Language.pptx

Notas do Editor

  1. Relational Databases store data organized i Tables that contains rows and columns Data is typically structured across multiple tables, which can be joined together via a primary key or a foreign key.  Orders can have 1 or many order lines here, but one OrderLine/Detail belong to only
  2. There is a SQL language standard defined by the American National Standards Institute (ANSI). Each vendor adds their own variations and extensions. Declarative Language (define the output) vs Procedural/imperative language (sequence of instructions) Declarative languages express the logic of a computation without describing its control flow in detail. Declarative programming stands in contrast to imperative programming via imperative programming languages, where control flow is specified by serial orders (imperatives).
  3. T-SQL expands on the SQL standard to include procedural programming, local variables, various support functions for string processing, date processing, mathematics, etc. and changes to the DELETE and UPDATE statements. Stored procedures in SQL Server are executable server-side routines. The advantage of stored procedures is the ability to pass parameters.
  4. Data Definition Language (DDL) is the set of SQL statements that handles the definition of database objects, such as tables, views, and procedures. DDL includes statements such as CREATE, ALTER, and DROP. Data Manipulation Language (DML) is the set of SQL statements that focuses on querying and modifying data. DML statements include SELECT, INSERT, UPDATE, and DELETE. Data Control Language (DCL) is the set of SQL statements used to manage security permissions for users and objects. DCL includes statements such as GRANT, REVOKE, and DENY.
  5. Add an example for each and the outcome as a pop up animation SQL Keywords are case sensitive. Some DB configurations are setup to be case sensitive for Tables and Column names. This will be referred as the Collation. It can be setup at a Database Level, Table level or column level. SQL Server default collation is case insensitive. PostgreSQL is Case Sensitive by default
  6. DEMO Show *, columns selection, alias, Order by
  7. Show some filtering options such as LIKE , =, BETWEEN, AND, OR, NOT, IN, ANY, SOME Precedence
  8. Comparing to NULL returns UNKNOWN when using ANSI. SQL Server lets you turn ANSI NULL OFF and use other operators that will return TRUE or FALSE There are vendors built-in functions to handle nulls SELECT FirstName, ISNULL(MiddleName, 'None') AS MiddleIfAny, LastName FROM Sales.Customer;
  9. In is more meticulous, goes thru the entire set Exists, we don’t care how many times, if it finds it, then it is true, otherwise is null
  10. Most popular functions They are used in the select and having Maybe mention DISTINCT? NULL affects AVG
  11. Now that you've seen what each clause does, let's look at the order in which SQL Server actually evaluates them: The FROM clause is evaluated first, to provide the source rows for the rest of the statement. A virtual table is created and passed to the next step. The WHERE clause is next to be evaluated, filtering those rows from the source table that match a predicate. The filtered virtual table is passed to the next step. GROUP BY is next, organizing the rows in the virtual table according to unique values found in the GROUP BY list. A new virtual table is created, containing the list of groups, and is passed to the next step. From this point in the flow of operations, only columns in the GROUP BY list or aggregate functions may be referenced by other elements. The HAVING clause is evaluated next, filtering out entire groups based on its predicate. The virtual table created in step 3 is filtered and passed to the next step. The SELECT clause finally executes, determining which columns will appear in the query results. Because the SELECT clause is evaluated after the other steps, any column aliases (in our example, Orders) created there cannot be used in the GROUP BY or HAVING clause. The ORDER BY clause is the last to execute, sorting the rows as determined by its column list. https://learn.microsoft.com/en-us/training/modules/introduction-to-transact-sql/4-examine-select-statement
  12. Most Common JOINS Allow us to combine tables together