EXERCISE TOPIC▼
- Access exercises (91)
- C# exercises (79)
- Excel exercises (278)
- Power Apps exercises (13)
- Power Automate exercises (18)
- Power BI exercises (139)
- Python exercises (28)
- Report Builder exercises (141)
- SQL exercises (198)
- SSAS exercises (51)
- SSIS exercises (46)
- SSRS exercises (99)
- VBA exercises (85)
- Visual Basic exercises (46)
SQL EXERCISES▼
SQL EXERCISES▼
- Simple Queries (4)
- Setting criteria using WHERE (5)
- Calculations (7)
- Calculations using dates (4)
- Basic joins (8)
- More exotic joins (2)
- Aggregation and grouping (8)
- Views (5)
- Subqueries (5)
- Stored procedures (5)
- Variables (8)
- Parameters and return values (11)
- Testing conditions (1)
- Looping (3)
- Scalar functions (6)
- Transactions (5)
- Creating tables (5)
- Temporary tables and table variables (9)
- Table-valued functions (6)
- Derived tables and CTEs (13)
- Dynamic SQL (4)
- Pivots (2)
- Triggers (2)
- Archived (70)
SQL | Basic joins exercise | Link 3 tables together using inner joins and table aliases
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
Software ==> | SQL (198 exercises) |
Version ==> | Any version of SQL Server |
Topic ==> | Basic joins (8 exercises) |
Level ==> | Average difficulty |
Subject ==> | SQL training |
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
If you haven't already done so, run the script in the above folder to generate the Doctor Who database.
Write a query using inner joins to show all of the authors who have written episodes featuring the Daleks. You may find the following relationship diagram useful to refer to:

How to get from enemies to authors in 3 easy jumps.
You should find that there are 16 such episodes!
When you've finished, save this as Enough joins for now, then close it down.
The exercise says: LIST AUTHORS
select a.AuthorId, a.AuthorName
from tblAuthor a
inner join tblEpisode e
on a.AuthorId = e.AuthorId
inner join [tblEpisodeEnemy] EpEn
on EpEn.EpisodeId = E.EpisodeId
inner join [tblEnemy] enemy
on enemy.EnemyId = EpEn.EnemyId
WHERE enemy.EnemyName LIKE 'Daleks'
GROUP BY a.AuthorId, a.AuthorName
select [EpisodeEnemyId], e.[EnemyName],[EpisodeNumber],[AuthorName]
from [dbo].[tblEpisodeEnemy] as epe
inner join [dbo].[tblEnemy] as e
on epe.EnemyId= e.EnemyId
inner join [dbo].[tblEpisode] as e1
on epe.EpisodeId = e1.EpisodeId
inner join [dbo].[tblAuthor] as a
on e1.AuthorId= a.AuthorId
where EnemyName like '%Daleks%'
Use inner joins to link four tables to show Dr Who enemies by author.
USE DoctorWho
select a.AuthorId,a.AuthorName,
b.Title,b.episodetype,
c.EnemyId, d.EnemyName
from tblAuthor as a
inner join tblEpisode as b on
a.AuthorId = b.AuthorId
inner join tblEpisodeEnemy as c on
c.EpisodeId = b.EpisodeId
inner join tblEnemy as d on
d.EnemyId = c.EnemyId
where d.EnemyName = 'Daleks'
So is this the code?
use doctorwho
Select authorname
from tblauthor as a
inner join tblepisode as epi
on a.authorid = epi.authorid
inner join tblepisodeenemy as ene
on epi.episodeid = ene.episodeenemyid
inner join tblenemy as enemy
on enemy.enemyid = ene.episodeenemyid
where title like '%Daleks%'
I just get only four rows ,
Select
x.AuthorName,y.EpisodeNumber,y.Title,y.EpisodeDate
From Author As x
INNER JOIN Episode As y
ON x.AuthorId = y.AuthorId
Where Title Like '%Daleks%';
Is this query correct?
You're showing all the episodes whose titles contain the word Dalek, rather than all episodes which feature the Daleks. So for example an episode entitled "Little tin men from space" might feature the Daleks, but wouldn't appear in your query.