What is SQL?
A language to manage and query data in relational databases.
What is a table in SQL?
A set of rows and columns that stores related data.
What is a primary key?
A column that uniquely identifies each row in a table.
What is a foreign key?
A column that links to the primary key of another table.
How do you get data from a table?
Use SELECT.
How do you insert data into a table?
Use INSERT INTO.
How do you update data in a table?
Use UPDATE with SET and WHERE.
How do you delete data from a table?
Use DELETE FROM with WHERE.
How do you filter rows?
Use WHERE clause.
How do you sort results?
Use ORDER BY.
How do you limit the number of rows?
Use LIMIT.
What is an INNER JOIN?
Returns matching rows from both tables.
What is a LEFT JOIN?
Returns all rows from the left table, even if there’s no match in the right.
What is a RIGHT JOIN?
Returns all rows from the right table, even if there’s no match in the left.
What is a FULL OUTER JOIN?
Returns all rows from both tables, with NULLs where there’s no match.
How do you count rows?
Use COUNT().
How do you find the average value?
Use AVG().
How do you find the total sum?
Use SUM().
How do you group data?
Use GROUP BY.
How do you filter grouped results?
Use HAVING.
What is an index in SQL?
A structure that speeds up searches on a column.
When should you create an index?
When a column is used often in WHERE, JOIN, or ORDER BY.
How do you check query performance?
Use EXPLAIN before the query.
How do you optimize a slow query?
Use EXPLAIN, add indexes, avoid SELECT *, and rewrite joins.