Lesson 3: SQL Queries
Queries
What is SQL?
SQL (Structured Query Language) is a programming language used to communicate with data stored in a relational database management system. SQL syntax is similar to the English language, which makes it relatively easy to write, read, and interpret.
Queries
A query in itself is just a statement which declares what data we are looking for, where to find it in the database, and optionally, how to transform it before it is returned.
Getting data from a query
SELECT
column_1
, column_2
, column_3
FROM table;SELECT *
FROM table;SELECT
column_1 AS first_column
, column_2 AS second_column
, column_3 third_column
FROM table;Filtering data with a WHERE clause
To refine the data returned by a query, use the WHERE clause to specify conditions.
SELECT
column_1, column_2
FROM table
WHERE condition;Example:
SELECT
name, age
FROM employees
WHERE age > 30;This query selects the name and age columns from the employees table, returning only rows where the age is greater than 30.
Last updated