0
0
MySQLquery~5 mins

Subqueries in FROM clause (derived tables) in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a subquery in the FROM clause called?
A subquery in the FROM clause is called a derived table. It acts like a temporary table that you can query from.
Click to reveal answer
beginner
Why use a derived table in a query?
Derived tables help break complex queries into smaller parts. They let you calculate or filter data first, then use that result as a table for further queries.
Click to reveal answer
beginner
How do you give a name to a derived table?
You must give an alias (a temporary name) to a derived table using AS alias_name right after the subquery.
Click to reveal answer
intermediate
Example: What does this query do?<br>
SELECT dt.category, COUNT(*) FROM (SELECT category FROM products WHERE price > 100) AS dt GROUP BY dt.category;
This query first selects products with price greater than 100 inside the derived table named dt. Then it counts how many products are in each category from that filtered list.
Click to reveal answer
intermediate
Can a derived table contain joins or aggregations?
Yes! A derived table can include joins, aggregations, or any valid SELECT query. It acts like a normal table for the outer query.
Click to reveal answer
What must you always provide when using a subquery in the FROM clause?
AA WHERE clause
BAn alias name
CA GROUP BY clause
DAn ORDER BY clause
Which of these is true about derived tables?
AThey act like temporary tables inside a query
BThey can only select columns, no calculations allowed
CThey must be created before the main query runs
DThey cannot be used with GROUP BY
What is the main benefit of using a derived table?
ATo speed up the database server
BTo permanently store data
CTo avoid using indexes
DTo simplify complex queries by breaking them into parts
Can a derived table include a JOIN inside its subquery?
AOnly INNER JOIN is allowed
BNo, joins are not allowed in derived tables
CYes, it can include joins
DOnly LEFT JOIN is allowed
Which clause is NOT required inside a derived table?
AWHERE
BSELECT
CFROM
DAS alias
Explain what a derived table is and why you would use one in a SQL query.
Think about how you can use a small table inside a bigger query.
You got /4 concepts.
    Describe the syntax and rules for writing a subquery in the FROM clause.
    Focus on how the subquery looks and how the outer query uses it.
    You got /4 concepts.