The document discusses various SQL concepts including DISTINCT, ORDER BY, GROUP BY, JOIN, nested queries, and aggregate functions. DISTINCT removes duplicate rows. ORDER BY sorts result rows. GROUP BY groups rows based on column values. JOIN combines data from multiple tables. Nested queries allow querying results of other queries. Aggregate functions perform calculations across multiple rows like COUNT, SUM, AVG, MIN, MAX.
Structured Query Language (SQL) is used to manage and query data in relational database management systems. The document discusses various SQL clauses such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and JOIN that are used to retrieve and manipulate data. It also covers aggregate functions, nested queries, different types of joins (inner, outer, self), and how nested queries can be rewritten as equivalent join queries.
SQL Data Manipulation Language presentationanandapriya
1) Structured Query Language (SQL) is used to manage data in relational database management systems.
2) SQL statements like SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY are used to query and manipulate data.
3) Joins allow data from multiple tables to be combined while filtering rows through conditions. Nested queries allow queries to be nested within other queries.
SQL is a standard language for accessing and manipulating databases. It allows users to query, insert, update, and delete data. The document discusses SQL statements like SELECT, INSERT, UPDATE, DELETE and functions like JOIN, aggregate functions, and scalar functions. It provides examples of creating tables and manipulating data using DDL, DML, and DCL statements. Joins allow combining data from multiple tables based on common fields.
This document provides an overview of querying and reporting in SQL, covering topics like arithmetic operators, built-in functions, selecting data, grouping results, joins, and subqueries. The agenda includes learning objectives, descriptions of SELECT statements, and explanations of concepts like aggregate functions, limiting results, sorting data, and correlating subqueries.
The document provides an introduction to SQL (Structured Query Language). It discusses the history and evolution of SQL standards. SQL is introduced as the most widely used and accepted language for managing data in relational database management systems. The key benefits of SQL and its role in creating, querying, updating and managing relational databases are described. Common SQL commands like CREATE, ALTER, DROP, INSERT, SELECT, UPDATE, DELETE are explained. Additional topics covered include functions, joins, subqueries and other advanced SQL features.
The document outlines SQL commands for creating and manipulating databases and tables, including creating and deleting databases and tables, inserting, updating, deleting and reading records from tables, and using clauses like WHERE, ORDER BY, GROUP BY and aggregate functions like COUNT, SUM, AVG, MIN, MAX. It also discusses set operations like UNION, INTERSECT, EXCEPT and using nested queries.
This document provides an outline of a SQL Lab tutorial covering MySQL. It introduces SQL and connecting to MySQL. It then covers various MySQL commands including administration commands, data definition language commands to create/drop databases and tables, data manipulation language commands to insert, retrieve, update and delete records, and more advanced queries using concepts like joins, aggregation, and pattern matching. SQL is introduced as a standard language for accessing and manipulating database systems and working with different database programs.
This document discusses SQL commands for defining and manipulating database tables. It covers creating tables with columns, primary keys, and foreign keys. It also covers SQL commands for data manipulation, including select statements, order by, aggregate functions, group by, subqueries, and joins. It emphasizes the importance of learning SQL through practice and provides references for further reading.
Structured Query Language (SQL) is used to manage and query data in relational database management systems. The document discusses various SQL clauses such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and JOIN that are used to retrieve and manipulate data. It also covers aggregate functions, nested queries, different types of joins (inner, outer, self), and how nested queries can be rewritten as equivalent join queries.
SQL Data Manipulation Language presentationanandapriya
1) Structured Query Language (SQL) is used to manage data in relational database management systems.
2) SQL statements like SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY are used to query and manipulate data.
3) Joins allow data from multiple tables to be combined while filtering rows through conditions. Nested queries allow queries to be nested within other queries.
SQL is a standard language for accessing and manipulating databases. It allows users to query, insert, update, and delete data. The document discusses SQL statements like SELECT, INSERT, UPDATE, DELETE and functions like JOIN, aggregate functions, and scalar functions. It provides examples of creating tables and manipulating data using DDL, DML, and DCL statements. Joins allow combining data from multiple tables based on common fields.
This document provides an overview of querying and reporting in SQL, covering topics like arithmetic operators, built-in functions, selecting data, grouping results, joins, and subqueries. The agenda includes learning objectives, descriptions of SELECT statements, and explanations of concepts like aggregate functions, limiting results, sorting data, and correlating subqueries.
The document provides an introduction to SQL (Structured Query Language). It discusses the history and evolution of SQL standards. SQL is introduced as the most widely used and accepted language for managing data in relational database management systems. The key benefits of SQL and its role in creating, querying, updating and managing relational databases are described. Common SQL commands like CREATE, ALTER, DROP, INSERT, SELECT, UPDATE, DELETE are explained. Additional topics covered include functions, joins, subqueries and other advanced SQL features.
The document outlines SQL commands for creating and manipulating databases and tables, including creating and deleting databases and tables, inserting, updating, deleting and reading records from tables, and using clauses like WHERE, ORDER BY, GROUP BY and aggregate functions like COUNT, SUM, AVG, MIN, MAX. It also discusses set operations like UNION, INTERSECT, EXCEPT and using nested queries.
This document provides an outline of a SQL Lab tutorial covering MySQL. It introduces SQL and connecting to MySQL. It then covers various MySQL commands including administration commands, data definition language commands to create/drop databases and tables, data manipulation language commands to insert, retrieve, update and delete records, and more advanced queries using concepts like joins, aggregation, and pattern matching. SQL is introduced as a standard language for accessing and manipulating database systems and working with different database programs.
This document discusses SQL commands for defining and manipulating database tables. It covers creating tables with columns, primary keys, and foreign keys. It also covers SQL commands for data manipulation, including select statements, order by, aggregate functions, group by, subqueries, and joins. It emphasizes the importance of learning SQL through practice and provides references for further reading.
MS SQL Server is a database server product of Microsoft that enables users to write and execute SQL queries and statements. It consists of several features like Query Analyzer, Profiler, and Service Manager. Profiler is a monitoring tool used for performance tuning. Service Manager helps manage SQL Server instances. Multiple instances can run on a single machine with each having independent users, databases, and settings. BCP is a command line utility that bulk copies data. Query Analyzer allows writing and executing SQL queries.
SQL is a language used to communicate with relational databases and manage data retrieval and storage. Key points:
- SQL allows users to perform tasks like updating or retrieving data from databases. It is the standard language used by relational database management systems.
- SQL uses structured queries to select, insert, update, delete and manage relational database tables. Common operations include filtering rows, projecting columns, joining tables, aggregating data, and grouping results.
- SQL syntax and capabilities vary slightly between different database implementations, but the core functionality remains the same. SQL allows powerful data analysis through features like subqueries, correlations, and aggregation.
This document provides a summary of MySQL indexes and how to use the EXPLAIN statement to analyze query performance. It defines what indexes are, the different types of indexes like B-tree, hash, and full-text indexes. It also explains concepts like compound indexes, covering indexes, and partial indexes. The document demonstrates how to use the EXPLAIN statement to view and understand a query execution plan, including analyzing the possible and actual indexes used, join types, number of rows examined, and index usage. It provides examples of interpreting EXPLAIN output and analyzing performance bottlenecks.
This document provides an overview of SQL analytic queries and tips and tricks, mostly related to PostgreSQL. It begins with an introduction on the topics to be covered, including SQL basics, advanced topics, and a conclusion. It then shares some lesser known facts about SQL, including that it is standardized, turing complete, and the only successful 4th generation programming language. The document reviews the revision history of SQL standards from 1986 to the present. It provides examples of common table expressions, temporary tables, unnesting and aggregation, subqueries, and lateral joins in SQL.
MS SQL Server is a database server product of Microsoft that allows users to write and execute SQL queries and statements. It consists of tools like Query Analyzer, Profiler, and Service Manager. Profiler is used for performance tuning. Service Manager helps manage SQL Server instances and databases can be created using the master database. SQL Server supports various data types, operators, and functions. Joins, indexes, views and other database objects are also supported to optimize queries and manage data.
This document provides an introduction to data models and SQL. It discusses the relational data model where data is stored in tables/relations with rows and columns. It describes keys such as primary and foreign keys. The document then introduces SQL commands for creating tables, inserting, updating, deleting and querying data. It provides examples of using SQL with the SQLite database and discusses physical data independence.
The document provides an overview of MS SQL Server including its key features like Query Analyzer, Profiler, Service Manager, and Bulk Copy Program. It discusses instances, databases, database objects, joins, views, functions and sequences. The summary focuses on the high-level topics covered in the document.
The document discusses SQL design patterns and relational division pattern in particular. It describes relational division as finding elements that belong to all sets in a collection of sets. It provides various implementations of relational division in SQL, including using minus, not exists, and grouping with a having clause to check for equality of counts.
This document summarizes an SQL programming workshop covering topics like joins, subqueries, unions, calculations, and grouping. The workshop covers inner, outer, left, and right joins. It also discusses correlated and uncorrelated subqueries, unions, calculated fields, string manipulation, date functions, and aggregate functions. Examples are provided for many of these SQL concepts.
Tame cloud complexity with F# powered DSLs (build stuff)Yan Cui
The emergence of Cloud platforms has fundamentally changed the IT landscape. However, attempting to ride on this ever-expanding platform ecosystem wave has created a new set of challenges.
Join Yan Cui in this talk as he draws on his extensive experience with AWS over the last 7 years to illustrate, with real-world use examples, how you can use F# to build internal and external DSLs to tame the complexity from these cloud services.
SMS Spam Filter Design Using R: A Machine Learning ApproachReza Rahimi
The document describes designing an SMS spam filter using machine learning techniques in R. It loads SMS data, extracts features to create vector space models of messages, and uses these to train classifiers like SVM with different kernels, KNN, and AdaBoost. Evaluation on test data shows classification accuracy for identifying spam vs ham messages. The filter provides an example of applying machine learning methods like text mining and classification to solve a real-world problem.
This document provides an introduction to key SQL concepts like nulls, group by, order by, distinct, and aggregates. It explains that nulls represent missing or unknown values and cannot be compared to other values. The group by clause groups result rows based on columns and can be used with aggregates. Order by sorts result rows based on columns. Distinct removes duplicate rows from results. Aggregates like count, sum, and average perform calculations across rows in a group.
This document provides an introduction to key SQL concepts like nulls, group by, order by, distinct, and aggregates. It explains that nulls represent missing or unknown values and cannot be compared to other values. The group by clause groups result rows based on columns and can be used with aggregates. Order by sorts result rows based on columns. Distinct removes duplicate rows from results. Aggregates like count, sum, and average perform calculations across rows in a group.
The document discusses various Python libraries used for data science tasks. It describes NumPy for numerical computing, SciPy for algorithms, Pandas for data structures and analysis, Scikit-Learn for machine learning, Matplotlib for visualization, and Seaborn which builds on Matplotlib. It also provides examples of loading data frames in Pandas, exploring and manipulating data, grouping and aggregating data, filtering, sorting, and handling missing values.
Integrity constraints are an important functionality of a DBMS that enable specification and enforcement of constraints. Examples include keys, foreign keys, and domain constraints. Keys uniquely identify tuples in a relation. Foreign keys require attributes of one relation to refer to keys of another relation. Functional dependencies specify that tuples agreeing on certain attributes must also agree on other attributes. Normalization aims to remove anomalies from relations by decomposing them according to dependencies. Relational algebra and calculus provide languages for querying relational databases. SQL is the most common language, allowing selection, projection, joins, and other operations on relations.
Integrity constraints are an important functionality of a DBMS that enable specification and enforcement of constraints. Examples include keys, foreign keys, and domain constraints. Keys uniquely identify tuples in a relation. Foreign keys require attributes of one relation to refer to keys of another relation. Functional dependencies specify that tuples agreeing on certain attributes must also agree on other attributes. Normalization aims to remove anomalies from relations by decomposing them according to dependencies. Relational algebra and calculus provide languages for querying relational databases. SQL is the most common language, allowing selection, projection, joins, grouping, aggregation, and modification of relations.
Performance Enhancements In Postgre Sql 8.4HighLoad2009
PostgreSQL 8.4 introduced several performance enhancements including optimizations to anti-joins, semi-joins, hash aggregation, and new free space map and visibility map features. It also included application-level improvements such as subqueries in LIMIT/OFFSET clauses, window functions, common table expressions, and parallel restore. Many changes provided performance benefits transparently to applications or DBAs while some required application changes to realize gains.
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxHAMEEDHUSSAINBU21CSE
Select statement is used to fetch data from one or more tables. It can use predicates like WHERE, GROUP BY, HAVING, and ORDER BY. The WHERE clause filters rows based on conditions, GROUP BY organizes rows into groups, HAVING applies conditions to groups, and ORDER BY sorts the results. Aggregate functions like COUNT, SUM, AVG, MAX, MIN perform calculations on multiple rows and return a single value.
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitForth
Vanessa Warheit, Co-Founder of EV Charging for All, gave this presentation at the Forth Addressing The Challenges of Charging at Multi-Family Housing webinar on June 11, 2024.
MS SQL Server is a database server product of Microsoft that enables users to write and execute SQL queries and statements. It consists of several features like Query Analyzer, Profiler, and Service Manager. Profiler is a monitoring tool used for performance tuning. Service Manager helps manage SQL Server instances. Multiple instances can run on a single machine with each having independent users, databases, and settings. BCP is a command line utility that bulk copies data. Query Analyzer allows writing and executing SQL queries.
SQL is a language used to communicate with relational databases and manage data retrieval and storage. Key points:
- SQL allows users to perform tasks like updating or retrieving data from databases. It is the standard language used by relational database management systems.
- SQL uses structured queries to select, insert, update, delete and manage relational database tables. Common operations include filtering rows, projecting columns, joining tables, aggregating data, and grouping results.
- SQL syntax and capabilities vary slightly between different database implementations, but the core functionality remains the same. SQL allows powerful data analysis through features like subqueries, correlations, and aggregation.
This document provides a summary of MySQL indexes and how to use the EXPLAIN statement to analyze query performance. It defines what indexes are, the different types of indexes like B-tree, hash, and full-text indexes. It also explains concepts like compound indexes, covering indexes, and partial indexes. The document demonstrates how to use the EXPLAIN statement to view and understand a query execution plan, including analyzing the possible and actual indexes used, join types, number of rows examined, and index usage. It provides examples of interpreting EXPLAIN output and analyzing performance bottlenecks.
This document provides an overview of SQL analytic queries and tips and tricks, mostly related to PostgreSQL. It begins with an introduction on the topics to be covered, including SQL basics, advanced topics, and a conclusion. It then shares some lesser known facts about SQL, including that it is standardized, turing complete, and the only successful 4th generation programming language. The document reviews the revision history of SQL standards from 1986 to the present. It provides examples of common table expressions, temporary tables, unnesting and aggregation, subqueries, and lateral joins in SQL.
MS SQL Server is a database server product of Microsoft that allows users to write and execute SQL queries and statements. It consists of tools like Query Analyzer, Profiler, and Service Manager. Profiler is used for performance tuning. Service Manager helps manage SQL Server instances and databases can be created using the master database. SQL Server supports various data types, operators, and functions. Joins, indexes, views and other database objects are also supported to optimize queries and manage data.
This document provides an introduction to data models and SQL. It discusses the relational data model where data is stored in tables/relations with rows and columns. It describes keys such as primary and foreign keys. The document then introduces SQL commands for creating tables, inserting, updating, deleting and querying data. It provides examples of using SQL with the SQLite database and discusses physical data independence.
The document provides an overview of MS SQL Server including its key features like Query Analyzer, Profiler, Service Manager, and Bulk Copy Program. It discusses instances, databases, database objects, joins, views, functions and sequences. The summary focuses on the high-level topics covered in the document.
The document discusses SQL design patterns and relational division pattern in particular. It describes relational division as finding elements that belong to all sets in a collection of sets. It provides various implementations of relational division in SQL, including using minus, not exists, and grouping with a having clause to check for equality of counts.
This document summarizes an SQL programming workshop covering topics like joins, subqueries, unions, calculations, and grouping. The workshop covers inner, outer, left, and right joins. It also discusses correlated and uncorrelated subqueries, unions, calculated fields, string manipulation, date functions, and aggregate functions. Examples are provided for many of these SQL concepts.
Tame cloud complexity with F# powered DSLs (build stuff)Yan Cui
The emergence of Cloud platforms has fundamentally changed the IT landscape. However, attempting to ride on this ever-expanding platform ecosystem wave has created a new set of challenges.
Join Yan Cui in this talk as he draws on his extensive experience with AWS over the last 7 years to illustrate, with real-world use examples, how you can use F# to build internal and external DSLs to tame the complexity from these cloud services.
SMS Spam Filter Design Using R: A Machine Learning ApproachReza Rahimi
The document describes designing an SMS spam filter using machine learning techniques in R. It loads SMS data, extracts features to create vector space models of messages, and uses these to train classifiers like SVM with different kernels, KNN, and AdaBoost. Evaluation on test data shows classification accuracy for identifying spam vs ham messages. The filter provides an example of applying machine learning methods like text mining and classification to solve a real-world problem.
This document provides an introduction to key SQL concepts like nulls, group by, order by, distinct, and aggregates. It explains that nulls represent missing or unknown values and cannot be compared to other values. The group by clause groups result rows based on columns and can be used with aggregates. Order by sorts result rows based on columns. Distinct removes duplicate rows from results. Aggregates like count, sum, and average perform calculations across rows in a group.
This document provides an introduction to key SQL concepts like nulls, group by, order by, distinct, and aggregates. It explains that nulls represent missing or unknown values and cannot be compared to other values. The group by clause groups result rows based on columns and can be used with aggregates. Order by sorts result rows based on columns. Distinct removes duplicate rows from results. Aggregates like count, sum, and average perform calculations across rows in a group.
The document discusses various Python libraries used for data science tasks. It describes NumPy for numerical computing, SciPy for algorithms, Pandas for data structures and analysis, Scikit-Learn for machine learning, Matplotlib for visualization, and Seaborn which builds on Matplotlib. It also provides examples of loading data frames in Pandas, exploring and manipulating data, grouping and aggregating data, filtering, sorting, and handling missing values.
Integrity constraints are an important functionality of a DBMS that enable specification and enforcement of constraints. Examples include keys, foreign keys, and domain constraints. Keys uniquely identify tuples in a relation. Foreign keys require attributes of one relation to refer to keys of another relation. Functional dependencies specify that tuples agreeing on certain attributes must also agree on other attributes. Normalization aims to remove anomalies from relations by decomposing them according to dependencies. Relational algebra and calculus provide languages for querying relational databases. SQL is the most common language, allowing selection, projection, joins, and other operations on relations.
Integrity constraints are an important functionality of a DBMS that enable specification and enforcement of constraints. Examples include keys, foreign keys, and domain constraints. Keys uniquely identify tuples in a relation. Foreign keys require attributes of one relation to refer to keys of another relation. Functional dependencies specify that tuples agreeing on certain attributes must also agree on other attributes. Normalization aims to remove anomalies from relations by decomposing them according to dependencies. Relational algebra and calculus provide languages for querying relational databases. SQL is the most common language, allowing selection, projection, joins, grouping, aggregation, and modification of relations.
Performance Enhancements In Postgre Sql 8.4HighLoad2009
PostgreSQL 8.4 introduced several performance enhancements including optimizations to anti-joins, semi-joins, hash aggregation, and new free space map and visibility map features. It also included application-level improvements such as subqueries in LIMIT/OFFSET clauses, window functions, common table expressions, and parallel restore. Many changes provided performance benefits transparently to applications or DBAs while some required application changes to realize gains.
Unit 3-Select Options and Aggregate Functions in SQL (1).pptxHAMEEDHUSSAINBU21CSE
Select statement is used to fetch data from one or more tables. It can use predicates like WHERE, GROUP BY, HAVING, and ORDER BY. The WHERE clause filters rows based on conditions, GROUP BY organizes rows into groups, HAVING applies conditions to groups, and ORDER BY sorts the results. Aggregate functions like COUNT, SUM, AVG, MAX, MIN perform calculations on multiple rows and return a single value.
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitForth
Vanessa Warheit, Co-Founder of EV Charging for All, gave this presentation at the Forth Addressing The Challenges of Charging at Multi-Family Housing webinar on June 11, 2024.
Ever been troubled by the blinking sign and didn’t know what to do?
Here’s a handy guide to dashboard symbols so that you’ll never be confused again!
Save them for later and save the trouble!
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill RoadsSprinter Gurus
Unlock the secrets behind your Mercedes Sprinter's uphill power loss with our comprehensive presentation. From fuel filter blockages to turbocharger troubles, we uncover the culprits and empower you to reclaim your vehicle's peak performance. Conquer every ascent with confidence and ensure a thrilling journey every time.
Understanding Catalytic Converter Theft:
What is a Catalytic Converter?: Learn about the function of catalytic converters in vehicles and why they are targeted by thieves.
Why are They Stolen?: Discover the valuable metals inside catalytic converters (such as platinum, palladium, and rhodium) that make them attractive to criminals.
Steps to Prevent Catalytic Converter Theft:
Parking Strategies: Tips on where and how to park your vehicle to reduce the risk of theft, such as parking in well-lit areas or secure garages.
Protective Devices: Overview of various anti-theft devices available, including catalytic converter locks, shields, and alarms.
Etching and Marking: The benefits of etching your vehicle’s VIN on the catalytic converter or using a catalytic converter marking kit to make it traceable and less appealing to thieves.
Surveillance and Monitoring: Recommendations for using security cameras and motion-sensor lights to deter thieves.
Statistics and Insights:
Theft Rates by Borough: Analysis of data to determine which borough in NYC experiences the highest rate of catalytic converter thefts.
Recent Trends: Current trends and patterns in catalytic converter thefts to help you stay aware of emerging hotspots and tactics used by thieves.
Benefits of This Presentation:
Awareness: Increase your awareness about catalytic converter theft and its impact on vehicle owners.
Practical Tips: Gain actionable insights and tips to effectively prevent catalytic converter theft.
Local Insights: Understand the specific risks in different NYC boroughs, helping you take targeted preventive measures.
This presentation aims to equip you with the knowledge and tools needed to protect your vehicle from catalytic converter theft, ensuring you are prepared and proactive in safeguarding your property.
Welcome to ASP Cranes, your trusted partner for crane solutions in Raipur, Chhattisgarh! With years of experience and a commitment to excellence, we offer a comprehensive range of crane services tailored to meet your lifting and material handling needs.
At ASP Cranes, we understand the importance of reliable and efficient crane operations in various industries, from construction and manufacturing to logistics and infrastructure development. That's why we strive to deliver top-notch solutions that enhance productivity, safety, and cost-effectiveness for our clients.
Our services include:
Crane Rental: Whether you need a crawler crane for heavy lifting or a hydraulic crane for versatile operations, we have a diverse fleet of well-maintained cranes available for rent. Our rental options are flexible and can be customized to suit your project requirements.
Crane Sales: Looking to invest in a crane for your business? We offer a wide selection of new and used cranes from leading manufacturers, ensuring you find the perfect equipment to match your needs and budget.
Crane Maintenance and Repair: To ensure optimal performance and safety, regular maintenance and timely repairs are essential for cranes. Our team of skilled technicians provides comprehensive maintenance and repair services to keep your equipment running smoothly and minimize downtime.
Crane Operator Training: Proper training is crucial for safe and efficient crane operation. We offer specialized training programs conducted by certified instructors to equip operators with the skills and knowledge they need to handle cranes effectively.
Custom Solutions: We understand that every project is unique, which is why we offer custom crane solutions tailored to your specific requirements. Whether you need modifications, attachments, or specialized equipment, we can design and implement solutions that meet your needs.
At ASP Cranes, customer satisfaction is our top priority. We are dedicated to delivering reliable, cost-effective, and innovative crane solutions that exceed expectations. Contact us today to learn more about our services and how we can support your project in Raipur, Chhattisgarh, and beyond. Let ASP Cranes be your trusted partner for all your crane needs!
EV Charging at MFH Properties by Whitaker JamiesonForth
Whitaker Jamieson, Senior Specialist at Forth, gave this presentation at the Forth Addressing The Challenges of Charging at Multi-Family Housing webinar on June 11, 2024.
Implementing ELDs or Electronic Logging Devices is slowly but surely becoming the norm in fleet management. Why? Well, integrating ELDs and associated connected vehicle solutions like fleet tracking devices lets businesses and their in-house fleet managers reap several benefits. Check out the post below to learn more.
1. SQL – DISTINCT
• Eliminates all the duplicate entries in the table resulting from the query.
Syntax:
Select [DISTINCT] select_list
From table[, table, …]
[Where expression]
[Order By expression]
Example:
Select DISTINCT studio_id, director_id
From Movies
studio_id director_id
1 1
2 2
2 10
3 1
3 9
2. SQL – Order By
• Used to sort the results based on contents of a column
• Multiple levels of sort can be done by specifying
multiple columns
• An expression can be used in Order By clause
Syntax:
Select function(column)
From table1 [, table2 …]
[Where condition]
[Order By {Column | alias | position} [ASC | DESC]]
3. SQL – Order By
Example: Sort Movies by profits in Ascending order
Select MovieTitle, Gross, Budget, (Gross – Budget) as profits
From movies
Order BY profits
Great Escape
67.5 70 -2.5
Upside Down 54 50 4
Green Warrior 96 80 16
Blue Oranges 28 7 21
Movie_title Gross Budget Profit
4. Aggregate Queries – Group
By
• Categorizes the query results according to the contents of a
column in the database
• Multiple levels of subgroups can be created by specifying
multiple columns
Syntax:
Select column1, [column2, …]
From table [, table …]
[Where condition]
Group By column1, [column2, ….]
Having [Condition]
5. Aggregate Queries – Group
By
Example: Get # of movies by each director for each studio
Select studio_id, director_id, count(*)
From Movies
Group By director_id, studio_id
Example: Get # of movies by each studio ordered by studio_id
Select studio_id, count(*)
From Movies
Group By studio_id
Order By studio_id
6. Aggregate Queries – Group
By
Example:
Select studio_id, Sum(budget)
From movies
Group by studio_id
Having Sum(budget) > 60
Example:
Select studio_id, count(*)
From Movies
Group By studio_id
Order By studio_id
7. Aggregate Queries
• Aggregate queries provides a more holistic view of
the data by further processing the retrieved data.
• They can work on
– On all the rows in a table
– A subset of rows in a table selected using a where clause
– Groups of selected data organized using Group By clause.
Syntax:
Select function(column)
From <list of tables>
Where <condition>
Group By <list of columns>
Having <condition>
8. Aggregate Queries
• Functions:
– Sum() Returns a sum of the column
– Count()Returns a total number of rows returned by a query
– Avg() Returns the average of a column
– Min() Returns minimum value of the column returned by query
– Max() Returns maximum value of the column returned by query
Notes 1: Count function does not include columns containing null values in total
Notes 2: Count can be used with distinct to count the number of distinct rows
Example:
Query: Select sum(budget)
From movies
Where studio_id = 3
Output: Sum(budget)
---------------
65.1
9. SQL – Join
• A Join is a Query that combines data from multiple
tables
– Multiple tables are specified in the From Clause
– For two tables to be joined in a sensible manner, they need
to have data in common
Example:
Schema: Movies (movie_title, director_id, release_date)
People(person_fname, person_lname, person_id)
Query: Select movie_title, person_fname, person_lname
From Movies, People
Where director_id = person_id
10. SQL – Joining Condition
• For a useful Join query a joining condition is required
– Defined in where clause as relationships between columns
– Multiple conditions may be defined if multiple columns
shared
– More than two tables can be joined in a query
Example: Find people who live in same state as studio
Schema:
Studios(studio_id, studio_state, studio_name, studio_city)
People(person_fname, person_lname, person_id, person_state, person_city)
Query:
Select person_fname, person_lname, studio_name
From Movies, People
Where studio_city = person_city
AND studio_state = person_state
11. SQL – More than two tables
Example: Get title, director, studio, city for all movies in
the database
Schema:
Studios(studio_id, studio_state, studio_name, studio_city)
People(person_fname, person_lname, person_id, person_state, person_city)
Movies(movie_title, director_id, studio_id)
Query:
Select M.movie_title, M.studio_id, P.person_fname, P.person_lname,
S.studio_city
From Movies M, People P, Studio S
Where M.director_id = P.person_id
AND M.studio_id = P.person_id
12. SQL – Self Join
• Required to compare values within a single column
– Need to define aliases for the table names
Example: Find actors living in the same state
Schema:
People(person_fname, person_lname, person_id, person_state, person_city)
Query:
Select p1.person_id, p1.person_fname, p1.person_lname, p1.person_state
From People p1, People p2
Where p1.person_state = p2.person_state
AND p1.person_id != p2.person_id
Note: Distinct operator is critical because if there are more than two people
from any state each person will appear as many times as there are
people from the state
13. SQL-92 – Join
• More verbose than pervious versions of SQL
– Need to define aliases for the table names
• Separates the condition for joining from condition for filtering
Example: Find actors living in the same state
Schema:
People(person_fname, person_lname, person_id, person_state, person_city)
Movies(movie_title, director_id, studio_id)
Query:
Select movie_title, person_fname, person_lname
From Movies INNER JOIN People
ON director_id = person_id
Select movie_title, person_fname, person_lname
From Movies INNER JOIN People
ON director_id = person_id
Where studio_id = 1
14. SQL-92 – Multiple Table Join
Example: Get title, director, studio, city for all movies in database
Schema:
Studios(studio_id, studio_state, studio_name, studio_city)
People(person_fname, person_lname, person_id, person_state, person_city)
Movies(movie_title, director_id, studio_id)
Query:
Select Movies.movie_title, Movies.studio_id, Person.person_fname,
Person.person_lname, Studio.studio_city
From (People Inner Join
(Movies Inner Join Studio
On Studio.studio_id = Movie.studio_id)
On Movie.director_id = Person.person_id
15. SQL-92 – Left/Right Join
Example:
Schema:
People(person_fname, person_lname, person_id, person_state, person_city)
Movies(movie_id, movie_title, director_id, studio_id)
Location(movie_id, city, state)
Query:
Select movie_title, city, state
From Movies Left Join Locations
On Movies.movie_id = Locations.movie_id
Select movie_title, person_fname, person_lname
From Movies Right Join People
On Movies.director_id = Person.person_id
Includes all
non matched
movie titles
Includes
all people
not matching
to directors
16. Nested Queries
• A sub query is a query nested within another query
– The enclosing query also called outer query
– Nested query is called inner query
• There can be multiple levels of nesting
Example:
Select movie_title
From movies
Where director_id IN (
Select person_id
From People
Where person_state = ‘TX’)
17. Nested Queries - Types
Non-Correlated Sub Queries:
– Requires data required by outer query before it can be executed
– Inner query does not contain any reference to outer query
– Behaves like a function
Example:
People(person_fname, person_lname, person_id, person_state, person_city)
Movies(movie_id, movie_title, director_id, studio_id)
Select movie_title, studio_id
From Movies
Where director_id IN (
Select person_id
From People
Where person_state = ‘TX’)
Steps:
1. Subquery is executed
2. Subquery results are plugged into the outer query
3. The outer query is processed
18. Nested Queries - Types
Correlated Sub Queries:
– Contains reference to the outer query
– Behaves like a loop
Example:
People(person_fname, person_lname, person_id, person_state, person_city)
Cast_Movies(cast_member_id, role, movie_id)
Select person_fname, person_lname
From People p1
Where ‘Pam Green’ in (
Select role
From Cast_Movies
Where p1.person_id = cast_member_id
)
Steps:
– Contents of the table row in outer query are read
– Sub-query is executed using data in the row being processed.
– Results of the inner query are passed to the where in the outer query
– The Outer query is Processed
19. Equivalent Join Query
Example:
People(person_fname, person_lname, person_id, person_state, person_city)
Cast_Movies(cast_member_id, role, movie_id)
Select person_fname, person_lname
From People, Cast_Movies
Where Cast_member_id = person_id
And role = ‘Pam Green’