NetRVA

SQL Tutorial: Learn Select & From Statements - Beginner's Guide

Written by Michael Foutz | Jan 17, 2024 11:53:07 PM

 

Creating and Inserting Data into Tables

Understanding table creation and data insertion is crucial. Let's imagine we have two tables: 'employee_demographics' and 'employee_salary'.

Using SELECT and FROM Statements

The 'SELECT' statement specifies the columns you want to see:

SELECT first_name FROM employee_demographics;

This command shows only first names from the employee demographics table.

To display all columns in a table:

SELECT * FROM employee_demographics;

Filtering and Aggregating Data

SELECT TOP (useful for large tables):

SELECT TOP 5 * FROM employee_demographics;

DISTINCT (for unique values):

SELECT DISTINCT gender FROM employee_demographics;

Understanding MAX, MIN, and AVG

MAX (highest value in a column):

SELECT MAX(salary) FROM employee_salary;

MIN (lowest value):

SELECT MIN(salary) FROM employee_salary;

AVG (average value):

SELECT AVG(salary) FROM employee_salary;

Using COUNT and AS

COUNT (counts non-null values):

SELECT COUNT(last_name) FROM employee_demographics;

AS (renames output column):

SELECT COUNT(last_name) AS 'Last Name Count' FROM employee_demographics;

Understanding the FROM Statement

The 'FROM' statement is crucial when working with specific tables:

SELECT * FROM [database_name].[dbo].[table_name];

Stay tuned for more SQL basics and complex concepts in future posts. For a more detailed walkthrough, check out the full video on NetRVA Academy's YouTube channel!