SQL Querying for Beginners Tutorial

Learnit Training2 minutes read

SQL is an industry standard for manipulating data from databases since the 1980s, with functions like queries, views, stored procedures, and permissions. The course covers a wide range of topics including querying, conditions, wildcards, dates, aggregates, sorting, grouping, ranking, filtering, joining tables, subqueries, and data exportation.

Insights

  • SQL is a standardized language used to manage databases by executing queries to find, insert, update, or delete records, as well as create and delete database objects like tables and views.
  • Views in SQL provide customized data displays for efficient user interaction, while stored procedures automate tasks, managing permissions for database objects and controlling user access levels.
  • SQL queries structure using keywords like SELECT, FROM, CREATE TABLE, and WHERE, with additional clauses like "between," "in," and wildcards for filtering and partial matches, as well as functions for manipulating dates and summarizing financial and numerical data.
  • Joining tables in SQL is crucial for combining data from multiple sources, with different join types like inner, left, and right joins offering varied result sets, while subqueries combine separate queries, and exporting data involves selecting, copying, and pasting results for sharing and further analysis.

Get key ideas from YouTube videos. It’s free

Recent questions

  • What is SQL used for?

    SQL is used to retrieve and manipulate data from databases.

  • How can SQL automate tasks?

    SQL can automate tasks with stored procedures.

  • What are SQL views?

    Views in SQL offer customized data display.

  • How can SQL manage user access?

    SQL manages permissions for database objects.

  • What are SQL keywords?

    SQL keywords like SELECT, FROM, WHERE structure queries.

Related videos

Summary

00:00

"SQL: Essential Language for Database Management"

  • SQL stands for Structured Query Language, used to retrieve and manipulate data from databases.
  • SQL is an industry standard since the early 1980s, with a consistent structure across platforms.
  • SQL can execute queries to find data, insert, update, or delete records in tables.
  • SQL can create and delete database objects like tables and views.
  • Views in SQL offer customized data display for efficient user interaction.
  • SQL can automate tasks with stored procedures, streamlining database maintenance.
  • SQL manages permissions for database objects, controlling user access levels.
  • To follow the course, install SQL Server Express by Microsoft for practical learning.
  • SQL keywords like SELECT, FROM, CREATE TABLE, and WHERE structure queries.
  • Connecting to a database through SQL Server Management Studio initiates query writing.

18:00

Database Infrastructure: Creating Tables and More

  • The course delves into database infrastructure, but focuses on familiar sections like creating tables.
  • The "create table" statement is highlighted, showcasing the creation of the employees table with specified columns and data types.
  • Details next to column names indicate data type, character limits, and nullability, which will be further discussed.
  • Indexes are mentioned as performance enhancers, with more tables being created to visualize the database structure.
  • Views, serving as windows into tables, are created later in the file for exploration in the course.
  • Insert statements are introduced to load data into tables, showcasing the type and actual values being inserted.
  • Executing the script to create the database involves clicking the "execute" button or using the shortcut key F5.
  • Upon execution, a messages window displays the completion status, ensuring successful creation.
  • Troubleshooting error messages is advised by researching Microsoft's error message resources and potentially recopying the script.
  • To view the new database, closing and logging back into Management Studio is necessary, revealing the Northwind database in the databases list.

33:11

Efficient SQL Table Filtering and Selection

  • Right-click on a table to get the first 1000 rows and view all columns.
  • Drag and drop columns from the left column view to the right to preset syntax.
  • Enter commas to separate field values when dragging columns.
  • Columns can be ordered in any desired sequence.
  • Typing column names without formal syntax can still generate results.
  • Use the asterisk wildcard character in SQL to select all columns in a table.
  • Filter criteria can be added using a WHERE clause in SQL queries.
  • Use "AND" to add multiple criteria for filtering results.
  • Use "OR" to search for multiple criteria where one or the other must be met.
  • Utilize "NULL" and "NOT NULL" conditions to filter based on empty or populated values.

50:28

SQL Comments, Clauses, Wildcards, and Aliases

  • SQL comments are denoted by special characters to prevent execution.
  • Two dashes signify a one-line comment, while a block of text requires special characters.
  • The "between" and "in" clauses are used to filter data in SQL queries.
  • The "between" clause selects values within a specified range.
  • The "in" clause selects multiple values from a column.
  • Examples of SQL queries using the "between" and "in" clauses are provided.
  • Wildcard characters, specifically the percent sign (%), are used to find partial matches in SQL queries.
  • An example demonstrates using the wildcard character to filter data.
  • An exercise prompts creating SQL statements using wildcard characters.
  • The importance of column aliases for formatting SQL query results is explained.

01:07:06

Enhancing SQL Queries for User-Friendly Data

  • The text discusses using an editor to ensure correct syntax and formatting in SQL queries.
  • It mentions changing column headers in a query to make the data more user-friendly.
  • The text highlights identifying and correcting syntax errors in SQL queries.
  • It emphasizes changing column headers like company name to title and postal code to zip code for clarity.
  • The importance of making data more user-friendly for sharing with the user community is stressed.
  • Instructions are given to change address to street address and phone to company phone in the customers table.
  • The process of changing column headers and formatting data values, specifically dates, is explained.
  • The text introduces functions like date add and date diff in SQL for manipulating date values.
  • Examples are provided for calculating the difference between dates and adding time to dates.
  • Exercises are given for readers to practice using date add and date diff functions in SQL queries.

01:22:31

"Summarizing Data Values with Functions"

  • Summarizing values in a dataset involves averaging, counting, and summing up values to derive results.
  • Functions covered in this lesson include average, sum, count, min, and max for financial and numerical manipulation.
  • Count function determines the number of rows in a table, aiding in query management and analysis.
  • Average function calculates the average value of a specific field in the table.
  • Sum function provides the accumulated value of a set of records in the table.
  • Min function identifies the minimum value in the result set, while max function reveals the maximum value.
  • Aggregated queries require grouping by additional columns for precise results.
  • Practical application involves using specific fields like unit price for financial calculations.
  • Exercises involve calculating accumulated unit price values and counting rows in tables.
  • Next lesson will focus on manipulating text values using functions like concatenate and substring for combining and extracting specific text portions.

01:37:40

Financial functions summarize, sort, and calculate data.

  • Financial functions help summarize financial values and sort them for relevance.
  • Order by arranges results based on a specified field's value in ascending or descending order.
  • Group by adds additional columns to summarized fields to display accumulated values.
  • Group by is crucial for showing the total value of each order in a database.
  • Attempting to mix detailed rows with aggregated values leads to an error message.
  • To resolve the error, use the group by clause to summarize other fields alongside financial information.
  • The having clause filters summarized data after calculation, unlike the where clause which filters before.
  • Rank assigns priority to results based on specified criteria, like country in this example.
  • The rank function doesn't always produce sequential numerical ranks due to various factors.
  • Mathematical functions can be applied to data to derive additional values, like calculating sales price based on a markup percentage.

01:54:00

"Markup, Sales Price, SQL Joins Explained"

  • To mark up a value by 20%, you multiply the unit price by 0.20 using mathematical operators like asterisk for multiplication.
  • The calculated markup for a unit price of 18 is 3.6, which is added to the original price to determine the sales price.
  • The sales price is obtained by adding the markup to the unit price, resulting in a sales price of 21.6 for a unit price of 18.
  • To find the total value of the unit price based on units in stock, multiply the unit price by the number of units in stock.
  • Calculating the difference between units in stock and units on order helps in determining the shortage or surplus of products.
  • Mathematical expressions are utilized to derive values and make informed decisions based on the results.
  • Pivoting in SQL allows for transforming rows into columns to present data in a more organized manner.
  • The pivot function in SQL requires specifying the fields to pivot on and the columns to display the accumulated values.
  • Joining tables in SQL is essential for combining data from multiple sources, with inner, left, and right joins offering different result sets.
  • Editing tables to ensure unique records in each table is crucial for demonstrating the functionality of joins accurately.

02:10:27

Essential Steps for Joining Tables in SQL

  • To join two tables, a common column is essential for linking records.
  • The territories table contains three columns: territory id, territory description, and region id.
  • The region table contains two columns: region id and region description.
  • An inner join is executed using the common column region id to link region and territories.
  • Aliases are used to reference columns when working with multiple tables.
  • Cartesian join, which results in duplicated rows, is avoided to ensure accurate information.
  • Columns from both territories and region tables are selected and linked using region id.
  • The join is executed by specifying territories to be joined with region on region id.
  • Left join includes all records from the table to the left of the join clause.
  • Right join includes all records from the table to the right of the join clause.

02:27:19

"Subqueries in SQL: Combining Queries Effectively"

  • The query aims to retrieve results excluding those also present in suppliers, resulting in 11 outcomes, with Boise omitted due to its presence in the suppliers table.
  • Subqueries are discussed as a method to combine separate queries into an overall query, particularly useful when extracting specific columns from various tables.
  • The example employs the customers and orders tables to demonstrate subquery functionality, linking them through employee IDs.
  • Subqueries necessitate aliases for clarity, with table references like 'c' for customers and 'o' for orders to streamline coding intelligently.
  • Troubleshooting duplicate records in subqueries involves understanding the grouping logic and ensuring proper referencing of columns from both source queries.
  • To eliminate duplicate records in subqueries, aggregate functions must be applied at the end, specifying individual columns for grouping.
  • The lesson concludes with a task for readers to identify orders shipped to Brazil using subqueries with the order details and orders tables.
  • Exporting data from SQL databases is crucial for sharing results with users, with options like copying and pasting into Excel or utilizing SQL coding functions for automated exports.
  • The process of exporting data involves selecting rows, copying with headers, and pasting into Excel for further formatting, or saving results directly to a chosen location.
  • The tutorial hints at more advanced methods for exporting data using SQL coding functions, emphasizing the importance of tailoring the export process to suit user needs.

02:43:32

"File saving, SQL basics, live classes offered"

  • The process involves naming and saving a file, defaulting to CSV but with the option to choose a different format like TXT. After saving, the file can be opened to view the results, which are raw data that can be manipulated in various applications. The SQL course covered connecting to a database, querying, using conditions and wildcards, date calculations, summarizing data with aggregate functions, sorting, grouping, ranking, filtering data, joining tables, combining queries, subqueries, and exporting data. The course also offers live classes, office applications, professional development, and private training at learnit.com.
Channel avatarChannel avatarChannel avatarChannel avatarChannel avatar

Try it yourself — It’s free.