MySQL Commands Overview
A quick guide on essential MySQL commands with
definitions, examples, and useful tips.
ORDER BY
Definition: The ORDER BY clause is used to sort the
result set of a query in ascending (ASC) or descending
(DESC) order based on one or more columns.
Example:
SELECT * FROM Employees
ORDER BY salary DESC, name ASC;
Useful Tip: Use ORDER BY with LIMIT to fetch top or
bottom records, e.g., highest or lowest salaries.
INSERT INTO
Definition: The INSERT INTO statement is used to add
new rows to a table. You can insert data into all
columns or specify only specific columns.
Example:
INSERT INTO Employees (name, position, salary)
VALUES ('John Doe', 'Developer', 60000);
Useful Tip: Use INSERT INTO ... SELECT to copy data
from one table to another.
UPDATE
Definition: he UPDATE statement modifies existing
records in a table. It can be used to change data in one
or multiple columns for specific rows.
Example:
UPDATE Employees
SET salary = 65000
WHERE name = 'John Doe';
Useful Tip: Always use a WHERE clause to avoid
updating all rows unintentionally.
NULL Values
Definition: NULL represents missing or unknown data
in a table. It’s different from an empty string or zero.
Example:
SELECT * FROM Employees
WHERE manager_id IS NULL;
Useful Tip: Use IS NULL and IS NOT NULL to filter for
NULL values, as = and != don’t work with NULL.
DELETE
Definition: he DELETE statement removes rows from a
table based on a specified condition.
Example:
DELETE FROM Employees
WHERE name = 'John Doe';
Useful Tip: Use DELETE FROM table_name without
WHERE cautiously, as it will delete all records. To
empty a table without removing its structure, consider
using TRUNCATE TABLE table_name.