SlideShare a Scribd company logo
1 of 39
Querying and Reporting  Module 3
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Learning Objectives
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Module 3 : Agenda
Module 3 : Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SELECT Statement ,[object Object],[object Object],[object Object],[object Object],[object Object],table is the name of the table column is the name of the column in the table to be selected condition identifies the rows to be selected and is composed of  column names, expressions, constraints, sub-queries and  comparison operators column is the name of the column(s) used for sorting (order by)
Querying and Reporting ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],Querying and Reporting (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Arithmetic Operators Modulo % Division / Addition + Multiplication * Subtraction - Operation Operator
Built in Functions ,[object Object],[object Object],[object Object],[object Object],[object Object]
Built In Functions : String Functions Returns part of a string.  Start s pecifies the character position at which the substring begins.  length  specifies the number of characters in the substring. substring ( expression ,  start ,  length ) Returns the reverse of the character or binary expression reverse ( expression ) Returns an integer representing the number of characters in a character expression or text value. char_length ( char_expr ) Returns the ASCII code for the first character in the expression. ascii ( char_expr ) Descriptions Functions
Built In Functions : Date Functions Returns date produced by adding datepart to given date. dateadd ( datepart , number,  date ) Returns the time between the first and second date. You can specify the datepart as months, years, hours, etc. datediff (datepart, date, date) Returns part of date as an integer. datepart ( datepart, date ) Returns Current system date and time. getdate () Descriptions Functions
Built In Functions : System Functions Returns the length of the column datalength ( expression ) Returns the computer name Host_name () Returns the process id of the process.  host_id ( ) Descriptions Functions
Use of Aggregate Functions ,[object Object],Total of the (distinct) values in the expression Sum ([all | distinct]  expression ) Lowest value in the expression Min ( expression ) Highest value in the expression Max ( expression ) Number of selected rows – including null values count(*) Number of (distinct) non-null values in the expression Count ([all | distinct]  expression ) Average of the (distinct) values in the expression Avg ([all | distinct]  expression ) Description Aggregate Function
Selecting Rows – Search Based ,[object Object],[object Object]
Rows may be limited by: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rows may be limited by: (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rows may be limited by: (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rows may be limited by: (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rows may be limited by: (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rows may be limited by: (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Rows may be limited by: (Continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sorting Rows ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],Grouping Result Sets ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],Grouping Result Sets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Joins ,[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Joins - Syntax
Joins – Cross Join ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Joins – Equi Join and Natural Join ,[object Object],[object Object],SELECT  au_fname, pub_name FROM  Authors, Publishers Where Authors.city=Publishers.city ,[object Object],[object Object],[object Object]
Joins – Self Join ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Joins – Outer Join ,[object Object],[object Object],[object Object],[object Object],[object Object],SELECT  * FROM  titles LEFT JOIN titileauthor  ON titiles.title_id = titleauthor.title_id
Joins – Outer Join SELECT  * FROM  titles RIGHT JOIN titileauthor  ON titiles.title_id = titleauthor.title_id SELECT  * FROM  titles FULL OUTER JOIN titileauthor  ON titiles.title_id = titleauthor.title_id
Sub Queries ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sub Queries (Continued) ,[object Object],SELECT  title, price FROM  titles WHERE price = ( SELECT  price FROM  titles WHERE  title = 'Straight Talk About Computers')
Sub Queries (Continued) ,[object Object],[object Object],SELECT  pub_name FROM  publishers  WHERE  pub_id  IN (SELECT  pub_id  FROM  titles  WHERE type = ‘business’)
[object Object],Sub Queries (Continued) SELECT  pub_name FROM  publishers  WHERE  EXISTS (SELECT  *  FROM  titles  WHERE pub_id = publishers.pub_id   AND  type = ‘business’)
[object Object],Sub Queries (Continued) SELECT  table1.type FROM  titles table1  WHERE  table1.type  IN  (SELECT table2.type  FROM  titles table2 WHERE table1. pub_id  ! =  table2. pub_id  )
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Resources
Key Points ,[object Object],[object Object]
Questions & Comments

More Related Content

What's hot

Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
Syed Zaid Irshad
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Achmad Solichin
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
Achmad Solichin
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
Vikas Gupta
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
Logan Palanisamy
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
Syed Zaid Irshad
 

What's hot (19)

Les17
Les17Les17
Les17
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Sql select
Sql select Sql select
Sql select
 
ALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMSALL ABOUT SQL AND RDBMS
ALL ABOUT SQL AND RDBMS
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 

Viewers also liked

Transact sql data definition language - ddl- reference
Transact sql data definition language - ddl- referenceTransact sql data definition language - ddl- reference
Transact sql data definition language - ddl- reference
Steve Xu
 
5 tsssisu sql_server_2012
5 tsssisu sql_server_20125 tsssisu sql_server_2012
5 tsssisu sql_server_2012
Steve Xu
 
X query language reference
X query language referenceX query language reference
X query language reference
Steve Xu
 
Css introduction
Css introductionCss introduction
Css introduction
Sridhar P
 
Sql server ___________session3-normailzation
Sql server  ___________session3-normailzationSql server  ___________session3-normailzation
Sql server ___________session3-normailzation
Ehtisham Ali
 
High Performance Front-End Development
High Performance Front-End DevelopmentHigh Performance Front-End Development
High Performance Front-End Development
drywallbmb
 
Multidimensional model programming
Multidimensional model programmingMultidimensional model programming
Multidimensional model programming
Steve Xu
 
Spatialware_2_Sql08
Spatialware_2_Sql08Spatialware_2_Sql08
Spatialware_2_Sql08
Mike Osbourn
 

Viewers also liked (20)

Transact sql data definition language - ddl- reference
Transact sql data definition language - ddl- referenceTransact sql data definition language - ddl- reference
Transact sql data definition language - ddl- reference
 
Module02
Module02Module02
Module02
 
5 tsssisu sql_server_2012
5 tsssisu sql_server_20125 tsssisu sql_server_2012
5 tsssisu sql_server_2012
 
X query language reference
X query language referenceX query language reference
X query language reference
 
Module01
Module01Module01
Module01
 
Module06
Module06Module06
Module06
 
Module08
Module08Module08
Module08
 
SQL Server 2008 Spatial Data - Getting Started
SQL Server 2008 Spatial Data - Getting StartedSQL Server 2008 Spatial Data - Getting Started
SQL Server 2008 Spatial Data - Getting Started
 
Sql Server Data Tools - Codenamed JUNEAU
Sql Server Data Tools - Codenamed JUNEAUSql Server Data Tools - Codenamed JUNEAU
Sql Server Data Tools - Codenamed JUNEAU
 
Module04
Module04Module04
Module04
 
Module05
Module05Module05
Module05
 
Alasql.js - SQL сервер на JavaScript
Alasql.js - SQL сервер на JavaScriptAlasql.js - SQL сервер на JavaScript
Alasql.js - SQL сервер на JavaScript
 
Css introduction
Css introductionCss introduction
Css introduction
 
Sql server ___________session3-normailzation
Sql server  ___________session3-normailzationSql server  ___________session3-normailzation
Sql server ___________session3-normailzation
 
SQL Server 2008 for .NET Developers
SQL Server 2008 for .NET DevelopersSQL Server 2008 for .NET Developers
SQL Server 2008 for .NET Developers
 
High Performance Front-End Development
High Performance Front-End DevelopmentHigh Performance Front-End Development
High Performance Front-End Development
 
AlaSQL библиотека для обработки JavaScript данных (презентация для ForntEnd 2...
AlaSQL библиотека для обработки JavaScript данных (презентация для ForntEnd 2...AlaSQL библиотека для обработки JavaScript данных (презентация для ForntEnd 2...
AlaSQL библиотека для обработки JavaScript данных (презентация для ForntEnd 2...
 
Multidimensional model programming
Multidimensional model programmingMultidimensional model programming
Multidimensional model programming
 
Spatialware_2_Sql08
Spatialware_2_Sql08Spatialware_2_Sql08
Spatialware_2_Sql08
 
Module07
Module07Module07
Module07
 

Similar to Module03

Similar to Module03 (20)

Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Les06
Les06Les06
Les06
 
Structured query language(sql)
Structured query language(sql)Structured query language(sql)
Structured query language(sql)
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
 
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)
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 
SQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptxSQLSERVERQUERIES.pptx
SQLSERVERQUERIES.pptx
 
Ejb5
Ejb5Ejb5
Ejb5
 
CIS245 sql
CIS245 sqlCIS245 sql
CIS245 sql
 
Les04
Les04Les04
Les04
 
SQL
SQLSQL
SQL
 
Les04
Les04Les04
Les04
 
12. Basic SQL Queries (2).pptx
12. Basic SQL Queries  (2).pptx12. Basic SQL Queries  (2).pptx
12. Basic SQL Queries (2).pptx
 
MySQL-commands.pdf
MySQL-commands.pdfMySQL-commands.pdf
MySQL-commands.pdf
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
5. Group Functions
5. Group Functions5. Group Functions
5. Group Functions
 
Les05
Les05Les05
Les05
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Module03

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Arithmetic Operators Modulo % Division / Addition + Multiplication * Subtraction - Operation Operator
  • 9.
  • 10. Built In Functions : String Functions Returns part of a string. Start s pecifies the character position at which the substring begins. length specifies the number of characters in the substring. substring ( expression , start , length ) Returns the reverse of the character or binary expression reverse ( expression ) Returns an integer representing the number of characters in a character expression or text value. char_length ( char_expr ) Returns the ASCII code for the first character in the expression. ascii ( char_expr ) Descriptions Functions
  • 11. Built In Functions : Date Functions Returns date produced by adding datepart to given date. dateadd ( datepart , number, date ) Returns the time between the first and second date. You can specify the datepart as months, years, hours, etc. datediff (datepart, date, date) Returns part of date as an integer. datepart ( datepart, date ) Returns Current system date and time. getdate () Descriptions Functions
  • 12. Built In Functions : System Functions Returns the length of the column datalength ( expression ) Returns the computer name Host_name () Returns the process id of the process. host_id ( ) Descriptions Functions
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. Joins – Outer Join SELECT * FROM titles RIGHT JOIN titileauthor ON titiles.title_id = titleauthor.title_id SELECT * FROM titles FULL OUTER JOIN titileauthor ON titiles.title_id = titleauthor.title_id
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.

Editor's Notes

  1. Faculty Notes: Select - CHOOSE the columns in a table that you want returned by your query Where - FILTER the rows in a table that you want returned by your query Order By - SORT data selected from the table in a specified order
  2. Faculty Notes : Char_length function returns the number of character for variable-length data in a table column. However for fixed-length data, it returns the defined length of the column. Reverse(expression) returns reverse of the characters for example if expression is “abcd”, it returns “dcba” Substring(expression, start, length) Returns part of a string where start specifies the character position at which the substring begins. length specifies the number of characters in the substring.
  3. Faculty Notes : Datepart notations are given below- Year abbreviated as yy expects values 1753–9999 Quarter abbreviated as qq expected values 1–4 Month abbreviated as mm expected values 1–12 Week abbreviated as wk expected values 1–54 Day abbreviated as dd expected values 1–31 Dayofyear abbreviated as dy expected values 1–366 Weekday abbreviated as dw expected values 1– 7 (Sunday–Saturday) hour abbreviated as hh expected values 0–23 Minute abbreviated as mi expected values 0–59 Second abbreviated as ss expected values 0–59 millisecond abbreviated as ms expected values 0–999
  4. Faculty Notes : Examples : select datalength('aaa') select host_id() select suser_name()
  5. Faculty Notes: The aggregate functions work with any type of column; however there are few exceptions: sum and avg functions work only with the numeric columns of int, smallint, tinyint, decimal, numeric, float, and money. Min and max functions will not work with bit data types Only the count(*) works with text and image data types. Example : Use pubs go select sum(ytd_sales) [Total Sales] from titles select count (*)[Total Records], avg (price*2)[Average Price] from titles --counts null values as well select count (price)[Total Not Null Records], avg (price*2) [Average Price] from titles --doesn't count null values Select max (ytd_sales)[Max Sales], min (ytd_sales) [Max Sales] from titles
  6. Faculty Notes: WHERE Clause Specifies the condition for the rows returned by a query. Syntax WHERE < search_condition > Arguments <search_condition> Defines the condition to be met for the rows to be returned. There is no limit to the number of predicates in <search_condition>.
  7. Faculty Notes: Read the above slide. Read both the select statements. Explain the output of each statement as follows: The first statement displays the last name and salary of employees whose salary is equal to 30000 The second statement displays the Employee Id and Last name for employees whose manager name is ‘RAYMOND’
  8. Faculty Notes: Read the Select statements. Explain the output of each statement as follows: The first statement displays the last name of employees whose salary is greater than 30000 The second statement displays the Employee Id and Last Name of employees whose salary is less than equal to 30000 The third statement displays the Employee Id whose Status is not ‘ACTIVE’
  9. Faculty Notes: Between condition takes into account the lower and the upper limit In the above example the select statement will display last name of employees whose salary is between 30000 and 50000 including 30000 and 50000 IN condition takes into account on the values supplied In the above example the select statement will display employee id of employees whose manager id is 100 or 200 or 300
  10. Faculty Notes: % Matches any string of zero or more characters. This wildcard character can be used as either a prefix or a suffix. The above Select statement displays the last name of all employees ending with ‘ram’ from the employee table Example: ‘%ram’ will fetch all those values which end in ‘ram’ ram , program, monogram, gram _ (under score) Matches any single character, and can be used as either a prefix or suffix. The above Select statement displays the last name of all employees ending with ‘at’ from the employee table and whose length is three characters. Example: bat , rat, sat, hat You can search for wildcard characters (% , _) also. There are two methods for specifying a character that would ordinarily be a wildcard: Use the ESCAPE keyword to define an escape character. When the escape character is placed in front of the wildcard in the pattern, the wildcard is interpreted as a character. For example, to search for the string 5% anywhere in a string, use: WHERE ColumnA LIKE '%5/%%' ESCAPE '/' In this LIKE clause, the leading and ending percent signs (%) are interpreted as wildcards, and the percent sign preceded by a slash (/) is interpreted as the % character.
  11. Faculty Notes: In the above examples: Select statement will display last name , job id of all employees whose salary is less than equal to 15000 AND job id is ‘SE’ Select statement will display last name , job id of all employees whose salary is less than equal to 15000 OR job id is ‘SE’
  12. Faculty Notes: Select statement will display last name , job id of all employees whose salary is less than equal to 15000 and NOT job id is ‘SE’
  13. Faculty Notes : Distinct returns non repeating values To returns the first n rows mentioned in the function Percent returns the n percent rows from the total rows. This n value can range only between 0-100
  14. Faculty Notes: Step through and explain the slide.
  15. Faculty Notes: Joins Join conditions can be specified in either the FROM or WHERE clauses; specifying them in the FROM clause is recommended. WHERE and HAVING clauses can also contain search conditions to further filter the rows selected by the join conditions.
  16. Faculty Notes : A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The following example shows a Transact-SQL cross join. See ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/c4f98374-e8a7-4f73-8d0e-309bd94ad1ae.htm for more information.
  17. Faculty Notes : Joins can be categorized as: Inner joins (the typical join operation, which uses some comparison operator like = or <>). These include equi-joins and natural joins. Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same in both the students and courses tables. The above stored procedure contains a select statement with INNER JOINS In above example, you can use a self-join to find out which authors in Oakland, California, live in the same postal code area. Since this query involves a join of the authors table with itself, the authors table appears in two roles. To distinguish these roles, you can temporarily and arbitrarily give the authors table two different correlation names—such as au1 and au2—in the from clause. These correlation names qualify the column names in the rest of the query.
  18. Faculty Notes : Outer joins : Outer joins can be a left, a right, or full outer join. Outer joins are specified with one of the following sets of keywords when they are specified in the FROM clause: LEFT JOIN or LEFT OUTER JOIN The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table. RIGHT JOIN or RIGHT OUTER JOIN. A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table. FULL JOIN or FULL OUTER JOIN. A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables. Cross joins. Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
  19. Faculty Notes : RIGHT JOIN or RIGHT OUTER JOIN. A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table. FULL JOIN or FULL OUTER JOIN. A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables. Cross joins. Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
  20. Faculty Notes: Review the key points on the slide. The key points should be used to summarize the content covered throughout this presentation.