SQL Course Introduction
- 42Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is a database?
A collection of data stored in a format that can be easily accessed.
Or swipe the card
42 cards
What is a database?
A collection of data stored in a format that can be easily accessed.
What is a DBMS?
Database Management System – software used to manage databases, execute instructions for querying or modifying data.
What are the two main categories of databases?
Relational (SQL) and Non-relational (NoSQL).
What is SQL used for?
To work with relational database management systems – querying and modifying data.
What is the historical significance of the name 'SQL'?
Originally called SEQUEL (Structured English Query Language), but the acronym was changed to SQL because SEQUEL was trademarked by an airplane company.
Which relational DBMS is used in the course and why?
MySQL – the most popular open source database in the world.
How do you select a database in MySQL?
Use the
USEstatement:USE database_name;or double-click the database in the navigator panel.What is the basic syntax of a SELECT statement?
SELECT columns FROM table WHERE condition ORDER BY column LIMIT number;How do you select all columns from a table?
SELECT * FROM table_name;How do you create an alias for a column?
SELECT column_name AS alias FROM table;– the AS keyword is optional.How do you remove duplicate rows from a result set?
Use the
DISTINCTkeyword:SELECT DISTINCT column FROM table;What arithmetic operators can be used in SQL?
Addition (+), subtraction (-), multiplication (*), division (/), modulus (%). Order of operations follows math: */ before +-.
How do you filter rows based on a condition?
Use the
WHEREclause with comparison operators:=,<>or!=,>,<,>=,<=.How do you combine multiple conditions?
Use
AND(both true),OR(at least one true), andNOT(negates).ANDhas higher precedence thanOR; use parentheses to override.How do you test if a column value is in a list?
Use the
INoperator:WHERE column IN (value1, value2, ...).How do you test if a column value falls within a range?
Use the
BETWEENoperator:WHERE column BETWEEN value1 AND value2– inclusive.What wildcards does the
LIKEoperator use?%matches any number of characters (including zero);_matches exactly one character.What special characters are used in
REGEXPfor pattern matching?^– beginning of string;$– end of string;|– logical OR;[]– match any single character listed;[a-z]– range.How do you check for NULL values?
Use
IS NULLorIS NOT NULL. Example:WHERE phone IS NULL.How do you sort query results?
Use
ORDER BY column1 [ASC|DESC], column2 .... Default is ascending (ASC).How do you limit the number of rows returned?
Use
LIMIT numberorLIMIT offset, number.LIMIT 3returns first 3 rows;LIMIT 6, 3skips 6 rows and returns 3.What is an INNER JOIN?
SELECT * FROM table1 JOIN table2 ON condition;Returns only rows where the join condition is true in both tables.How do you join tables from different databases?
Prefix the table name with the database name:
FROM db1.table1 JOIN db2.table2 ON ...What is a self join and how is it used?
Joining a table with itself using different aliases. Example:
FROM employees e JOIN employees m ON e.reports_to = m.employee_id.What is a compound join condition?
A join condition that uses multiple columns with AND. Example:
ON t1.col1 = t2.col1 AND t1.col2 = t2.col2.What is the difference between INNER and OUTER joins?
INNER JOIN returns only matching rows; LEFT JOIN returns all rows from the left table, with NULLs for non-matching right table; RIGHT JOIN is the opposite.
How does the
USINGclause simplify joins?FROM table1 JOIN table2 USING (common_column);– works when the column name is identical in both tables.What is a natural join and why is it discouraged?
FROM table1 NATURAL JOIN table2;– The database engine automatically joins on all columns with the same name.What is a cross join?
Combines every row from the first table with every row from the second table. Syntax:
FROM table1 CROSS JOIN table2orFROM table1, table2(implicit).How does the
UNIONoperator work?Combines results from multiple SELECT statements into one result set. The number of columns in each SELECT must be equal.
How do you insert a single row into a table?
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);How do you insert multiple rows in one statement?
INSERT INTO table_name (columns) VALUES (row1), (row2), ...;How do you insert hierarchical data (parent and child rows)?
Insert the parent row, then use
LAST_INSERT_ID()to get the generated ID for the child rows. Example:INSERT INTO orders ...; INSERT INTO order_items (order_id, ...) VALUES (LAST_INSERT_ID(), ...);How do you create a copy of a table using a subquery?
CREATE TABLE new_table AS SELECT * FROM existing_table;How do you insert data from one table into another using a subquery?
INSERT INTO target_table SELECT ... FROM source_table WHERE condition;What is the syntax for updating rows?
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;How do you use expressions in UPDATE statements?
You can set a column to an expression involving other columns, e.g.,
SET points = points + 15orSET payment_total = invoice_total * 0.5.How do you use a subquery in an UPDATE statement?
Place the subquery inside parentheses in the WHERE clause. Example:
UPDATE invoices SET ... WHERE client_id = (SELECT client_id FROM clients WHERE name = 'Myworks');How do you delete rows from a table?
DELETE FROM table_name WHERE condition;– without WHERE, all rows are deleted.Why should you restore the databases after practicing DML operations?
To return the databases to their original state to avoid unexpected results in future exercises.
What is the correct order of clauses in a SELECT statement?
SELECT -> FROM -> WHERE -> ORDER BY -> LIMIT
How do you add comments in SQL?
Use
--for single-line comments or/* ... */for multi-line comments.

Ask anything
We've read this whole study set, so questions about it get the best answers.