SlideShare une entreprise Scribd logo
1  sur  15
Reddit SQL Lecture 2 Shane Smith
Recap
Parts of a database Record Tables Attribute/Field ,[object Object]
 Attributes/fields become “columns”
 Rules determine the relationship  between the tables and tie the data  together to form a database,[object Object]
The WHERE clause Helps parse results for specific criteria Multiple WHERE clauses can be strung together Will evaluate results based on order in which WHERE clauses occur Can help reduce cost if used properly, or increase if used improperly
WHERE clause syntax SELECT column_name(s) FROM table_name WHERE column_nameoperator‘value’ EX: SELECT name, phone_number, address FROM contacts WHERE zip code=‘32792’
Using AND and OR As queries become more complex, AND/OR can be used to parse results even further Used in conjunction with WHERE statements AND retrieves data that meet all criteria OR retrieves data that meet any criteria Both can come at significant cost
Using AND/OR SELECT column_name(s) FROM table_name WHERE column_nameoperator ‘value’ AND column_nameoperator ‘value’ EX: SELECT name, phone_number, address FROM contacts WHERE zip code=32792 AND children=25
Sorting You can use ORDER BY to sort your results: SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC/DESC EX: SELECT name, phone_number, address FROM contacts WHERE zip code=32792 ORDER BY name ASC *Default order, if not specified is ASCENDING
Using IN You can use IN to specify multiple criteria for a WHERE statement Helps reduce query clutter Reduces query cost in some cases
Using IN SELECT column_name(s) FROM table_name WHERE column_nameIN (‘value1’, ‘value2’) EX: SELECT name, phone_number, address FROM contacts WHERE zip codeIN (‘32792’, ‘33707’)
Using BETWEEN The BETWEEN operator is used in a WHERE clause to select a range of data between two values SELECT column_name(s) FROM table_name WHERE column_name BETWEEN ‘value1’ AND ‘value2’
Using TOP The TOP clause is used to specify the number of records to return. The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance. TOP PERCENT can also be used
Using TOP SELECT TOP number|percentcolumn_name(s) FROM table_name EX: SELECT TOP 50 name, phone_number, address FROM contacts SELECT TOP 50 PERCENT name, phone_number, address FROM contacts

Contenu connexe

Tendances

Understanding databases and querying
Understanding databases and queryingUnderstanding databases and querying
Understanding databases and querying
Usman Sharif
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and Privileges
Ashwin Dinoriya
 
evaluation of statistical expression, materialised views, evaluation plans
evaluation of statistical expression, materialised views, evaluation plansevaluation of statistical expression, materialised views, evaluation plans
evaluation of statistical expression, materialised views, evaluation plans
Harsh Kotwani
 
spreedsheet operation
spreedsheet operationspreedsheet operation
spreedsheet operation
yamchhetri
 
Using vlookup in excel
Using vlookup in excelUsing vlookup in excel
Using vlookup in excel
megankilb
 
Sql basics
Sql basicsSql basics
Sql basics
Kumar
 

Tendances (19)

SQL
SQLSQL
SQL
 
SQL Data Manipulation
SQL Data ManipulationSQL Data Manipulation
SQL Data Manipulation
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Understanding databases and querying
Understanding databases and queryingUnderstanding databases and querying
Understanding databases and querying
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and Privileges
 
evaluation of statistical expression, materialised views, evaluation plans
evaluation of statistical expression, materialised views, evaluation plansevaluation of statistical expression, materialised views, evaluation plans
evaluation of statistical expression, materialised views, evaluation plans
 
Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813
 
Sql joins
Sql joinsSql joins
Sql joins
 
spreedsheet operation
spreedsheet operationspreedsheet operation
spreedsheet operation
 
Constraints
ConstraintsConstraints
Constraints
 
Vlookup Description
Vlookup DescriptionVlookup Description
Vlookup Description
 
SQL
SQLSQL
SQL
 
Functions of ms excel 2003
Functions of ms excel 2003Functions of ms excel 2003
Functions of ms excel 2003
 
Sql join
Sql  joinSql  join
Sql join
 
Using vlookup in excel
Using vlookup in excelUsing vlookup in excel
Using vlookup in excel
 
Sql basics
Sql basicsSql basics
Sql basics
 
Join sql
Join sqlJoin sql
Join sql
 

En vedette

Introducing The Shout Lounge
Introducing The Shout LoungeIntroducing The Shout Lounge
Introducing The Shout Lounge
linkup marketing
 
10hullartannisaahmed
10hullartannisaahmed10hullartannisaahmed
10hullartannisaahmed
Annisa Ahmed
 
Presentación1
Presentación1Presentación1
Presentación1
jonetajone
 
Kim alton hw420-section-unit5project
Kim alton hw420-section-unit5projectKim alton hw420-section-unit5project
Kim alton hw420-section-unit5project
Kim
 
Oral presentation PIQUÉ.
Oral presentation PIQUÉ.Oral presentation PIQUÉ.
Oral presentation PIQUÉ.
2juliaa
 
Claiming Your Foursquare Venue
Claiming Your Foursquare VenueClaiming Your Foursquare Venue
Claiming Your Foursquare Venue
linkup marketing
 

En vedette (15)

9 Tips for Facebook Timeline Page Layout
9 Tips for Facebook Timeline Page Layout9 Tips for Facebook Timeline Page Layout
9 Tips for Facebook Timeline Page Layout
 
Designprinciples
DesignprinciplesDesignprinciples
Designprinciples
 
Introducing The Shout Lounge
Introducing The Shout LoungeIntroducing The Shout Lounge
Introducing The Shout Lounge
 
10hullartannisaahmed
10hullartannisaahmed10hullartannisaahmed
10hullartannisaahmed
 
Claiming your Facebook Place
Claiming your Facebook PlaceClaiming your Facebook Place
Claiming your Facebook Place
 
Presentación1
Presentación1Presentación1
Presentación1
 
Uajshsmsi
UajshsmsiUajshsmsi
Uajshsmsi
 
10 Steps to Building a Viral Video
10 Steps to Building a Viral Video10 Steps to Building a Viral Video
10 Steps to Building a Viral Video
 
Sql1
Sql1Sql1
Sql1
 
Kim alton hw220 01-unit6_presentation
Kim alton hw220 01-unit6_presentationKim alton hw220 01-unit6_presentation
Kim alton hw220 01-unit6_presentation
 
Gta laptops 2013
Gta laptops 2013Gta laptops 2013
Gta laptops 2013
 
Kim alton hw420-section-unit5project
Kim alton hw420-section-unit5projectKim alton hw420-section-unit5project
Kim alton hw420-section-unit5project
 
Genetically modified agriculture in our food chain
Genetically modified agriculture in our food chainGenetically modified agriculture in our food chain
Genetically modified agriculture in our food chain
 
Oral presentation PIQUÉ.
Oral presentation PIQUÉ.Oral presentation PIQUÉ.
Oral presentation PIQUÉ.
 
Claiming Your Foursquare Venue
Claiming Your Foursquare VenueClaiming Your Foursquare Venue
Claiming Your Foursquare Venue
 

Similaire à Sql2

Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
Bishal Ghimire
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 

Similaire à Sql2 (20)

MY SQL
MY SQLMY SQL
MY SQL
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
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
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Chapter08
Chapter08Chapter08
Chapter08
 
SQL Query
SQL QuerySQL Query
SQL Query
 
98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt
 
06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
 
Sql2
Sql2Sql2
Sql2
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
 
SQL
SQLSQL
SQL
 
SQL
SQLSQL
SQL
 
Dbms
DbmsDbms
Dbms
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Query
QueryQuery
Query
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
 
SQL report
SQL reportSQL report
SQL report
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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?
 
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
 
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...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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...
 
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...
 

Sql2

  • 1. Reddit SQL Lecture 2 Shane Smith
  • 3.
  • 5.
  • 6. The WHERE clause Helps parse results for specific criteria Multiple WHERE clauses can be strung together Will evaluate results based on order in which WHERE clauses occur Can help reduce cost if used properly, or increase if used improperly
  • 7. WHERE clause syntax SELECT column_name(s) FROM table_name WHERE column_nameoperator‘value’ EX: SELECT name, phone_number, address FROM contacts WHERE zip code=‘32792’
  • 8. Using AND and OR As queries become more complex, AND/OR can be used to parse results even further Used in conjunction with WHERE statements AND retrieves data that meet all criteria OR retrieves data that meet any criteria Both can come at significant cost
  • 9. Using AND/OR SELECT column_name(s) FROM table_name WHERE column_nameoperator ‘value’ AND column_nameoperator ‘value’ EX: SELECT name, phone_number, address FROM contacts WHERE zip code=32792 AND children=25
  • 10. Sorting You can use ORDER BY to sort your results: SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC/DESC EX: SELECT name, phone_number, address FROM contacts WHERE zip code=32792 ORDER BY name ASC *Default order, if not specified is ASCENDING
  • 11. Using IN You can use IN to specify multiple criteria for a WHERE statement Helps reduce query clutter Reduces query cost in some cases
  • 12. Using IN SELECT column_name(s) FROM table_name WHERE column_nameIN (‘value1’, ‘value2’) EX: SELECT name, phone_number, address FROM contacts WHERE zip codeIN (‘32792’, ‘33707’)
  • 13. Using BETWEEN The BETWEEN operator is used in a WHERE clause to select a range of data between two values SELECT column_name(s) FROM table_name WHERE column_name BETWEEN ‘value1’ AND ‘value2’
  • 14. Using TOP The TOP clause is used to specify the number of records to return. The TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance. TOP PERCENT can also be used
  • 15. Using TOP SELECT TOP number|percentcolumn_name(s) FROM table_name EX: SELECT TOP 50 name, phone_number, address FROM contacts SELECT TOP 50 PERCENT name, phone_number, address FROM contacts
  • 16. TOP equivalents Not all DBMS’s use TOP MySQL uses LIMIT Oracle uses a WHERE statement with the value ROWNUM SELECT column_name(s) FROM table_name WHERE ROWNUM <= number