www.dageop.com
Optimising
Queries
ÂŽ
OQ-03 Distinguishing among query types
DR. SUBRAMANI
PARAMASIVAM
(MANI)
About
me
Dr. SubraMANI Paramasivam
PhD., MCT, MCSE, MCITP, MCP, MCTS, MCSA
CEO, Principal Consultant & Trainer
@ DAGEOP (UK)
Email: mani@dageop.com
Blog: http://dataap.org/blog
Follow
Us
https://www.facebook.com/pages/YOUR-SQL-MAN-LTD/
http://www.youtube.com/user/YourSQLMAN
https://twitter.com/dageop
https://uk.linkedin.com/in/dageop
Proud Sponsor
• SQLBits
• SQL Saturdays
• MCT Summit
• SQL Server Geeks
Summit
• Data Awareness
Programme
• Dageop’s Data Day
ÂŽ
www.DataAP.org
SPEAKER
Contents
• OQ-03 Distinguishing among query types
• Point
• Multipoint
• Range
• Prefix match
• Extremal
• Ordering
• Grouping
• Join
www.dageop.com
Optimizing Queries
OQ-03 Distinguishing among Query Types
www.dageop.com
Optimizing Queries
Point & Multipoint
www.dageop.com
Optimizing Queries
Point & Multipoint
• Spatial Data just representing the information about Location and
shape of the geometric objects.
• To locate a particular place, we can use the point with Latitude and
Longitude information.
• There are two spatial data types in SQL Server
• Geometry
• Geography
www.dageop.com
Optimizing Queries
Point & Multipoint
Syntax for Point
Point (Lat, Long, SRID)
Explanation:
Lat
• Is a float expression representing the x-coordinate of the Point being generated.
Long
• Is a float expression representing the y-coordinate of the Point being generated.
SRID
• Is an int expression representing the SRID of the geography instance you wish to
return.
www.dageop.com
Optimizing Queries
Point & Multipoint
Syntax
Multipoint (X coordinate, YZ coordinate, SRID)
Example for Multipoint
www.dageop.com
Optimizing Queries
Point & Multipoint
• What is the purpose of using Point?
Helps to find the distance between the
two cites by using geography point with
lat & long information
www.dageop.com
Optimizing Queries
DEMO
www.dageop.com
Optimizing Queries
Range
www.dageop.com
Optimizing Queries
Range
• In SQL Server we have Range search condition, it will return all values
between two specified values.
• Normally two types of Ranges
• Inclusive Range
• Exclusive Range
• Inclusive Range
• It will use the keyword called “BETWEEN”
• Exclusive Range
• It will use greater than or lesser than
www.dageop.com
Optimizing Queries
DEMO
www.dageop.com
Optimizing Queries
Prefix Match & Ordering
www.dageop.com
Optimizing Queries
Prefix Match & Ordering
• Helps to identify first few character or values of an attribute.
• “Like” operator is used
• ORDER BY is used and will not affect the data.
• ASC
• DESC
www.dageop.com
Optimizing Queries
SELECT
FROM
WHERE COL1 LIKE PREFIXCOL1+’%’
ORDER BY LEN(PREFIXCOL1) DESC
DEMO
www.dageop.com
Optimizing Queries
Extremal
• 2 different extremes in a query, it can be Min or Max
• It’s used to find the maximum value of the particular column of the
table or minimum value.
• Syntax:
Min (Column_Name)
Max(Column_Name)
www.dageop.com
Optimizing Queries
DEMO
www.dageop.com
Optimizing Queries
Grouping
www.dageop.com
Optimizing Queries
Grouping
• Helps in grouping the data and helps finding value for a group.
• GROUP BY helps to aggregate other values in a query.
• CUBE and ROLLUP cannot be used without GROUP BY.
www.dageop.com
Optimizing Queries
DEMO
www.dageop.com
Optimizing Queries
Joins
www.dageop.com
Optimizing Queries
Joins
• The SQL Joins is used to combine records from two or more tables.
• Why:
• To collect information with a common key column in tables
• Most commonly used joins are,
• Inner Join
• Outer Join
• Left Outer Join
• Right Outer Join
• Full Outer Join
www.dageop.com
Optimizing Queries
Joins
Inner Join
• Displays matched results
between two tables
www.dageop.com
Optimizing Queries
Joins
Left Outer Join:
Matching data from
both table as well as
everything from the table in
LEFT side.
Right Outer Join:
Matching data from
both table as well as
everything from the table in
RIGHT side.
www.dageop.com
Optimizing Queries
Joins
Full Outer Join
• Renders all the rows from both the tables based on the column used
to join.
www.dageop.com
Optimizing Queries
DEMO
www.dageop.com
Optimizing Queries
Review
Distinguishing among query types
Point
Multipoint
Range
Prefix match
Extremal
Ordering
Grouping
Join
www.dageop.com
Optimizing Queries
Q & A
www.dageop.com
Optimizing Queries
ÂŽ
www.dageop.com

Optimising Queries - Series 3 Distinguishing among query types