Learn Basic SQL in 15 Minutes | Business Intelligence For Beginners | SQL Tutorial For Beginners 1/3
Summary
This video introduces the fundamentals of SQL querying for business intelligence beginners. It covers selecting specific data, filtering rows using 'WHERE' with various operators (equality, LIKE, IN, BETWEEN, IS NULL/IS NOT NULL), sorting results with 'ORDER BY', joining tables using 'INNER JOIN', and aggregating data with functions like SUM, AVG, and COUNT, grouped by 'GROUP BY'. The 'HAVING' clause is also explained for filtering aggregated results. The tutorial emphasizes practical application for creating efficient data views and preparing data for BI tools.
Key Insights
SQL querying is essential for BI analysts, even with advanced BI tools.
While BI tools can generate queries for basic charts, analysts often need to write SQL to pre-aggregate, filter, and select specific data for efficient analysis, commonly through creating 'views'.
GROUP BY clause organizes rows for aggregation.
The GROUP BY clause is essential when using aggregate functions; it groups rows that have the same values in specified columns so the function operates on each group.
HAVING clause filters aggregated results.
Unlike WHERE (filters rows before aggregation), HAVING filters groups based on conditions applied to the aggregate function's results (e.g., HAVING AVG(rating) > 85).
Sections
Introduction to SQL Querying
SQL querying is essential for BI analysts, even with advanced BI tools.
While BI tools can generate queries for basic charts, analysts often need to write SQL to pre-aggregate, filter, and select specific data for efficient analysis, commonly through creating 'views'.
Focus is on selecting data, not database manipulation.
The tutorial will cover the essentials of querying (selecting) data from existing tables, not on creating or deleting databases or tables.
SQL is not case-sensitive but capitalization improves readability.
SQL keywords like SELECT and FROM are not case-sensitive, but capitalizing them and other keywords makes queries significantly easier to read, especially for complex statements.
Basic SELECT and WHERE Clauses
SELECT * retrieves all columns and rows from a table.
The basic syntax SELECT * FROM table_name; retrieves all available data from the specified table.
Specify columns to retrieve only desired fields.
Instead of '*', list the exact column names separated by commas (e.g., SELECT player_name, birthday FROM player;) to get only those fields.
Use AS to create aliases for selected fields.
The 'AS' keyword allows renaming columns in the result set for clarity (e.g., SELECT player_name AS name). Aliases with spaces require quotes.
The WHERE clause filters rows based on conditions.
Use the WHERE clause followed by conditions to return only specific rows that meet the criteria. Operators include '=', '>', '>=', '<', '<='.
Combine conditions with AND and OR operators.
Use 'AND' to require all conditions to be true and 'OR' to require at least one condition to be true for a row to be returned.
LIKE operator enables pattern matching in text fields.
The LIKE operator with '%' (wildcard for any sequence of characters) and '_' (wildcard for a single character) allows flexible text searching.
IN operator checks for multiple exact values.
The IN operator provides a concise way to filter for rows where a column matches any value in a specified list (e.g., WHERE player_name IN ('Ronaldo', 'Messi')). It requires exact matches, no wildcards.
BETWEEN operator selects values within a range (inclusive).
The BETWEEN operator filters rows where a numeric value falls within a specified range (e.g., WHERE weight BETWEEN 180 AND 190).
IS NULL and IS NOT NULL check for empty or non-empty fields.
These operators are used to identify rows where a specific field contains no data (IS NULL) or contains data (IS NOT NULL).
Sorting and Joining Data
ORDER BY clause sorts results by specified columns.
Use ORDER BY to sort the result set by one or more columns. 'ASC' (ascending) is the default; 'DESC' (descending) can be specified.
Joins combine data from multiple related tables.
To include data from different tables, use JOIN clauses. The example demonstrates an INNER JOIN to combine player attributes with player names based on a common ID.
Table aliases simplify queries with multiple tables.
Assign short aliases (e.g., 'a' for player_attributes, 'b' for player) to table names to make queries referencing fields from those tables much cleaner and easier to read.
Aggregating and Filtering Grouped Data
Aggregate functions summarize data (SUM, AVG, COUNT).
Functions like SUM(), AVG(), and COUNT() can be used to calculate totals, averages, or counts for groups of rows.
GROUP BY clause organizes rows for aggregation.
The GROUP BY clause is essential when using aggregate functions; it groups rows that have the same values in specified columns so the function operates on each group.
HAVING clause filters aggregated results.
Unlike WHERE (filters rows before aggregation), HAVING filters groups based on conditions applied to the aggregate function's results (e.g., HAVING AVG(rating) > 85).
Ask a Question
*Uses 1 Wisdom coin from your coin balance











