Explore tens of thousands of sets crafted by our community.
Common SQL Commands
20
Flashcards
0/20
DROP TABLE
Used to delete a table and its structure from the database. Example: DROP TABLE users;
DISTINCT
Used to remove duplicate rows from a result set. Example: SELECT DISTINCT country FROM users;
IN
Used to specify multiple possible values for a column. Example: SELECT * FROM users WHERE country IN ('USA', 'Canada');
ALTER TABLE
Used to modify an existing table's structure. Example: ALTER TABLE users ADD COLUMN email VARCHAR(100);
TRANSACTION
A sequence of database operations that are treated as a single logical unit. Example: BEGIN TRANSACTION; ... COMMIT;
UPDATE
Used to modify existing data in a table. Example: UPDATE users SET age = 26 WHERE name = 'Alice';
INDEX
Used to create an index on a table column to increase query performance. Example: CREATE INDEX idx_name ON users (name);
SELECT
Used to retrieve data from a database. Example: SELECT * FROM users;
CREATE TABLE
Used to create a new table in the database. Example: CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100), age INT);
LIMIT
Used to specify the maximum number of records to return. Example: SELECT * FROM users LIMIT 5;
UNION
Used to combine the result sets of two or more SELECT statements. Example: SELECT name FROM users UNION SELECT name FROM managers;
WHERE
Used to filter records that satisfy a specified condition. Example: SELECT * FROM users WHERE age >= 18;
CASE
Used for conditional logic in SQL statements. Example: SELECT name, CASE WHEN age < 18 THEN 'minor' ELSE 'adult' END AS type FROM users;
INSERT INTO
Used to insert new data into a table. Example: INSERT INTO users (name, age) VALUES ('Alice', 25);
HAVING
Used to filter groups based on a condition, often used with GROUP BY. Example: SELECT COUNT(*), country FROM users GROUP BY country HAVING COUNT(*) > 10;
ORDER BY
Used to sort the result set of a query. Example: SELECT name, age FROM users ORDER BY age DESC;
DELETE FROM
Used to remove existing data from a table. Example: DELETE FROM users WHERE name = 'Alice';
BETWEEN
Used to filter the result set within a certain range. Example: SELECT * FROM users WHERE age BETWEEN 18 AND 30;
JOIN
Used to combine rows from two or more tables based on a related column between them. Example: SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id;
GROUP BY
Used to arrange identical data into groups. Example: SELECT COUNT(*), country FROM users GROUP BY country;
© Hypatia.Tech. 2024 All rights reserved.