Welcome back to our SQL journey! In our previous posts, we’ve explored what SQL is, why it’s important, and how to set up your SQL environment. Now it’s time to delve into the heart of the language and learn the essential commands that allow you to interact with data stored in your database. These commands are your keys to unlocking the power of SQL and manipulating data like a pro.
SQL Commands: The Verbs of the Database World
In the realm of SQL, commands are like verbs – they tell the database what action to perform. We’ll focus on the four fundamental commands that form the foundation of data manipulation:
- SELECT: The star of the show, this command allows you to retrieve specific data from your database. Think of it as asking a question, and SELECT fetches the answer.
- INSERT: Use this command to add new records (rows) to your tables, expanding your dataset.
- UPDATE: Modify existing data within your tables to keep it accurate and up-to-date.
- DELETE: Remove unwanted or outdated records from your tables, ensuring data integrity.
SELECT: The Art of Asking Questions
Let’s start with SELECT, the workhorse of SQL. This command is how you query your database to find the information you need. The basic structure of a SELECT statement is:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Let’s break this down:
- SELECT column1, column2, …: Specify the columns (attributes) you want to retrieve from the table. To select all columns, use
*
. - FROM table_name: Indicate the table from which you want to retrieve data.
- WHERE condition: (Optional) Filter the results based on specific criteria.
Examples:
- Retrieve all columns from a table:
SELECT * FROM customers;
- Retrieve specific columns:
SELECT name, email FROM customers;
- Retrieve data with a filter:
SELECT * FROM products WHERE price < 100;
Going Beyond the Basics with SELECT:
The SELECT command is incredibly versatile. You can enhance your queries by adding:
- ORDER BY: Sort the results in ascending or descending order based on a specific column.
SELECT * FROM orders ORDER BY order_date DESC; -- Newest orders first
- LIMIT: Restrict the number of rows returned. Useful for paginating results or testing queries.
SELECT * FROM products LIMIT 10; -- Show only the first 10 products
- DISTINCT: Eliminate duplicate values in the result set.
SELECT DISTINCT category FROM products; -- Show unique product categories
- Functions: Perform calculations on your data (e.g., SUM, AVG, COUNT). We’ll explore functions in more detail in later posts.
INSERT: Populating Your Tables
The INSERT command allows you to add new records to your tables. The syntax is:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
- table_name: The table you want to insert data into.
- (column1, column2, …): The columns you want to fill with values.
- (value1, value2, …): The actual values to insert into the columns (make sure the order matches the column order).
Example:
INSERT INTO employees (name, email, department)
VALUES ('Alice', 'alice@example.com', 'Sales');
UPDATE: Keeping Your Data Fresh
The UPDATE command modifies existing records in your table. The syntax is:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
- table_name: The table you want to update.
- SET column1 = value1, …: Specify which columns to update and their new values.
- WHERE condition: (Optional but highly recommended!) Filter which rows to update based on a condition. Without a WHERE clause, you’ll update ALL rows in the table!
Example:
UPDATE products
SET price = 120
WHERE product_id = 10;
DELETE: Saying Goodbye to Data
The DELETE command removes records from your table. The syntax is:
DELETE FROM table_name
WHERE condition;
- table_name: The table you want to delete from.
- WHERE condition: (Optional but crucial!) Filter which rows to delete. Be extremely careful when omitting this, as you could accidentally delete everything!
Example:
DELETE FROM orders
WHERE order_date < '2023-01-01';
Caution with DELETE:
Always double-check your DELETE statements before executing them, especially when you don’t have a WHERE clause. You don’t want to accidentally erase valuable data!
Practice Makes Perfect
Now that you’ve learned the essential SQL commands, it’s time to put them into practice. Experiment with creating tables, inserting data, updating records, and deleting rows. The more you use these commands, the more comfortable you’ll become with manipulating data in your databases.
In the next installment, we’ll dive deeper into SQL, exploring more advanced concepts like joins, aggregate functions, and subqueries.
Until then, happy querying!
Cheers!
J
Check out the merch store for some cool analytics-inspired gear!

-
SQL Order Of Operations Coffee Mug$25.00
-
SQL Order of Operations Coffee Mug$22.00 – $25.00
-
SQL – Order of Operations Shirt$25.00 – $28.00
-
SQL – NVARCHAR Shirt$25.00 – $28.00
Share this:
- Click to share on X (Opens in new window) X
- Click to share on Facebook (Opens in new window) Facebook
- Click to print (Opens in new window) Print
- Click to share on Mastodon (Opens in new window) Mastodon
- Click to share on Telegram (Opens in new window) Telegram
- Click to share on WhatsApp (Opens in new window) WhatsApp
- Click to share on Pocket (Opens in new window) Pocket
- Click to share on Nextdoor (Opens in new window) Nextdoor
- Click to email a link to a friend (Opens in new window) Email
- Click to share on Pinterest (Opens in new window) Pinterest
- Click to share on Tumblr (Opens in new window) Tumblr
- Click to share on LinkedIn (Opens in new window) LinkedIn
- Click to share on Reddit (Opens in new window) Reddit