SlideShare a Scribd company logo
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

More Related Content

What's hot

SQL
SQLSQL
SQL Data Manipulation
SQL Data ManipulationSQL Data Manipulation
SQL Data Manipulation
khalid alkhafagi
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
Brian Gallagher
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
 
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
 
Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813Creating a vlookup v1.0 050813
Creating a vlookup v1.0 050813
Dave Shannon
 
Sql joins
Sql joinsSql joins
Sql joins
Gaurav Dhanwant
 
spreedsheet operation
spreedsheet operationspreedsheet operation
spreedsheet operation
yamchhetri
 
Constraints
ConstraintsConstraints
Constraints
Abrar ali
 
Vlookup Description
Vlookup DescriptionVlookup Description
Vlookup Description
Vijay Perepa
 
SQL
SQLSQL
Functions of ms excel 2003
Functions of ms excel 2003Functions of ms excel 2003
Functions of ms excel 2003
gaurav jain
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
Using vlookup in excel
Using vlookup in excelUsing vlookup in excel
Using vlookup in excel
megankilb
 
Sql basics
Sql basicsSql basics
Sql basics
Kumar
 
Join sql
Join sqlJoin sql
Join sql
Vikas Gupta
 

What's hot (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
 

Viewers also liked

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
linkup marketing
 
Designprinciples
DesignprinciplesDesignprinciples
Designprinciples
Sonia Davis Gutierrez
 
Introducing The Shout Lounge
Introducing The Shout LoungeIntroducing The Shout Lounge
Introducing The Shout Lounge
linkup marketing
 
10hullartannisaahmed
10hullartannisaahmed10hullartannisaahmed
10hullartannisaahmed
Annisa Ahmed
 
Claiming your Facebook Place
Claiming your Facebook PlaceClaiming your Facebook Place
Claiming your Facebook Place
linkup marketing
 
Presentación1
Presentación1Presentación1
Presentación1jonetajone
 
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
linkup marketing
 
Sql1
Sql1Sql1
Sql1
5h4m4n
 
Kim alton hw220 01-unit6_presentation
Kim alton hw220 01-unit6_presentationKim alton hw220 01-unit6_presentation
Kim alton hw220 01-unit6_presentation
Kim
 
Gta laptops 2013
Gta laptops 2013Gta laptops 2013
Gta laptops 2013
Alexis Vidal
 
Kim alton hw420-section-unit5project
Kim alton hw420-section-unit5projectKim alton hw420-section-unit5project
Kim alton hw420-section-unit5project
Kim
 
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
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
 

Viewers also liked (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
 

Similar to Sql2

MY SQL
MY SQLMY SQL
MY SQL
sundar
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
Cathie101
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
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
jainendraKUMAR55
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
PriyaPandey767008
 
Chapter08
Chapter08Chapter08
Chapter08
sasa_eldoby
 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
 
98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt98765432345671223Intro-to-PostgreSQL.ppt
98765432345671223Intro-to-PostgreSQL.ppt
HastavaramDineshKuma
 
06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
Bishal Ghimire
 
Sql2
Sql2Sql2
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
Yaser52
 
SQL
SQLSQL
SQL
SQLSQL
Dbms
DbmsDbms
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 
Query
QueryQuery
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
EllenGracePorras
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
Information Technology
 
SQL report
SQL reportSQL report
SQL report
Ahmad Zahid
 

Similar to 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
 

Recently uploaded

Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 

Recently uploaded (20)

Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 

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