Understanding table creation and data insertion is crucial. Let's imagine we have two tables: 'employee_demographics' and 'employee_salary'.
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;
SELECT TOP (useful for large tables):
SELECT TOP 5 * FROM employee_demographics;
DISTINCT (for unique values):
SELECT DISTINCT gender FROM employee_demographics;
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;
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;
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!