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
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

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:

Three tables linked

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.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 5 threads Add post
15 May 22 at 20:32

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

18 Dec 18 at 20:31

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%'


25 Sep 18 at 15:35

Use inner joins to link four tables to show Dr Who enemies by author.

USE DoctorWho
select a.AuthorId,a.AuthorName,
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'

05 Nov 17 at 18:42

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%'

25 Oct 17 at 07:14

I just get only four rows ,

From Author As x
INNER JOIN Episode As y
ON x.AuthorId = y.AuthorId
Where Title Like '%Daleks%';

Is this query correct?

19 Apr 18 at 06:32

Should have been ..

enemyname like' %Dalek%'

25 Oct 17 at 08:44

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.