0
0
SQLquery~5 mins

INNER JOIN with table aliases in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using table aliases in an INNER JOIN?
Table aliases give shorter or easier names to tables in a query. This makes the query simpler to write and read, especially when joining multiple tables.
Click to reveal answer
beginner
Write a simple INNER JOIN query using table aliases for tables employees and departments.
SELECT e.name, d.department_name FROM employees e INNER JOIN departments d ON e.department_id = d.id;
Click to reveal answer
beginner
In the query SELECT e.name FROM employees e INNER JOIN departments d ON e.department_id = d.id;, what do e and d represent?
They are aliases for the tables <code>employees</code> and <code>departments</code> respectively. They let you refer to these tables with shorter names.
Click to reveal answer
intermediate
Why is it important to use aliases when joining tables that have columns with the same name?
Aliases help specify which table a column belongs to, avoiding confusion and errors when columns have the same name in different tables.
Click to reveal answer
intermediate
Can you use any name as a table alias? Are there any rules?
Yes, you can use almost any name as an alias, but it should not be a reserved SQL keyword and should be easy to understand. It must follow SQL naming rules (no spaces, start with a letter, etc.).
Click to reveal answer
What does the alias e represent in this query? <br> SELECT e.name FROM employees e INNER JOIN departments d ON e.department_id = d.id;
AThe departments table
BThe employees table
CA column name
DA function
Why do we use INNER JOIN in SQL?
ATo combine rows from two tables where there is a match in both
BTo select all rows from the first table only
CTo delete rows from a table
DTo update rows in a table
Which of the following is a correct way to alias a table named orders?
Aorders AS *
Borders AS 123
Corders AS o
Dorders AS select
In an INNER JOIN with aliases, how do you refer to the id column from the second table aliased as d?
Ad.id
Bid.d
Cd->id
Did
What happens if you don’t use aliases in a query joining two tables with columns of the same name?
AThe query will run fine without issues
BThe columns will be ignored
CThe database will rename columns automatically
DThe query will fail or be ambiguous
Explain how to write an INNER JOIN query using table aliases and why aliases are helpful.
Think about how you can shorten table names and why that helps.
You got /4 concepts.
    Describe a situation where using table aliases in an INNER JOIN is necessary.
    Imagine two tables both have a column named 'id'.
    You got /3 concepts.