Demystifying SQL vs. MySQL - Key Query Difference
Demystifying SQL vs. MySQL - Key Query Difference
SELECT Retrieves data from one or more SELECT name, age FROM users;
tables.
INSERT Adds new records to a table. INSERT INTO users (name, age) VALUES
('Alice', 30);
UPDATE Modifies existing records in a table. UPDATE users SET age = 31 WHERE name =
'Alice';
DELETE Removes records from a table. DELETE FROM users WHERE name = 'Alice';
CREATE Creates anew table in the database. CREATE TABLE users (id INT PRIMARY KEY,
TABLE name VARCHAR (100), age INT);
ALTER TABLE Modifies an existing table structure, ALTERTABLE users ADD email VARCHAR (100);'
such as adding or dropping
columns.
DROP TABLE Deletes a table and all its data. DROP TABLE users;
DROP Deletes a database and all its data. DROP DATABASE my_database;'
DATABASE
SELECT Retrieves unique records from a SELECT DISTINCT age FRM users;
DISTINCT table.
WHERE Filters records that meet a specific SELECT name FROM users WHERE age > 25;
condition.
UNION Combines the result sets of two or *SELECT name FROM users UNION SELECT name
UNION ALL Combines the result sets of two or SELECT name FROM users UNION ALL SELECT
SUBQUERY A query nested inside another SELECT name FROM users WHERE age = (SELECT
query. MAX(age) FROM users);
EXISTS Checks if a subquery returns any SELECT name FROM users WHERE EXISTS (SELECT
records. 1 FROM orders WHERE users.id =
orders.user_id):
ANY Compares a value to any value in a 'SELECT name FROM users WHERE age > ANY
list or subquery. (SELECT age FROM users WHERE age < 30) ;
ALL Compares a value to all values in a SELECT name FROM users WHERE age> ALL
list or subquery. (SELECT age FROM users WHERE age < 30);
LIKE Searches for a specified pattern in a SELECT name FROM users WHERE name LIKE
column. 'A%';
IN Checks if a value is within a set of SELECT name FROM users WHERE age IN (25,
values. 30, 35);
BETWEEN Selects values within a range. 'SELECT name FROM users WHERE age BETWEEN 20
AND 30;
LIMIT Specifies the number of records to SELECT name FROM users LIMIT 5;
return.
WHERE Filters records that meet a specific SELECT name FROM users WHERE age > 25;
condition.
ORDER BY Sorts the result set by one or more *SELECT name, age FROM users ORDER BY age
columns. DESC;
GROUP BY Groups rows that have the same 'SELECT age, coUNT (*) FROM users GROUP BY
values into summary rows. age;
HAVING Filters groups based on a condition. SELECT age, couNT (*) FROM users GROUP BY
age HAVING COUNT (*) > 1;
JOIN Combines rows from two or more SELECT users.name, orders., amount FROM users
tables based on a related column. INNER JOIN orders ON users.id =
orders.user_id;
INNER JOIN Retrieves records with matching SELECT users.name, orders.amount FROM users
values in both tables. INNER JOIN orders ON users.id =
orders.user_id;
LEFT JOIN Retrieves all records from the left *SELECT users.name, orders.amount FROM users
table and matched records from the LEFT JOIN orders ON users.id =
right table. orders..user_ id;'
RIGHT JoIN Retrieves all records from the right SELECT users. name, orders. amount FROM users
table and matched records from the RIGHT JOIN orders ON users.id =
left table. orders.user_id;
FULL OUTER Retrieves records when there is a *SELECT users. name, orders.amount FROM users
JOIN match in one of the tables. FULL OUTER J0IN orders ON users.id =
orders. user_id;
LIMIT Specifies the number of records to 'SELECT name FROM users LIMIT 5;
return.
OFFSET Specifies the starting point for SELECT name FROM users LIMIT 5 OFFSET 10;
records to return.
CAST Converts a value from one data type SELECT name, CAST (age AS CHAR) FROM users;
to another.