Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
551 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | SQL (203 exercises) |
Topic ==> | Subqueries (8 exercises) |
Level ==> | Harder than average |
Subject ==> | SQL training |
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.
This will generate the database that you'll need to use in order to do this exercise (note that the database and script are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl).
Create a subquery to list out all of those events whose:
You'll need to use the words NOT IN, as well as TOP N ... DESC.
Your query should list these 8 events (shown here in chronological order):
These events occurred in countries and categories coming early in the alphabet.
Save this query as Early events, then close it down.
You can find other training resources for the subject of this exercise here:
From: | Bhavya59 |
When: | 02 Aug 24 at 12:30 |
SELECT EventName
,EventDetails
FROM tblEvent e
INNER JOIN tblCountry c ON e.CountryID=c.CountryID
INNER JOIN tblCategory ca ON e.CategoryID=ca.CategoryID
WHERE e.CountryID NOT IN(
SELECT TOP 30 CountryID FROM tblCountry
ORDER BY CountryName DESC
)
AND e.CategoryID NOT IN(
SELECT TOP 15 CategoryID FROM tblCategory
ORDER BY CategoryName DESC
)
From: | YUVA |
When: | 31 Jul 23 at 19:12 |
Select
E.eventname,
e.eventdetails
from tblEvent e inner join tblCountry c on e.CountryID=c.CountryID
where c.CountryID not in (select top 30 c.CountryID from tblCountry c order by c.CountryName desc) and
CategoryID not in (select top 15 k.CategoryID from tblCategory as k order by k.CategoryName desc)
From: | FelixP |
When: | 21 Mar 21 at 10:51 |
MYSQL solution
For mysql-typical error 1235 see this https://stackoverflow.com/questions/17892762/mysql-this-version-of-mysql-doesnt-yet-support-limit-in-all-any-some-subqu
SELECT EventName , EventDetails
FROM tblEvent e1
WHERE e1.CountryID NOT IN
( SELECT sub1.CountryID FROM -- wrapping due due Error code: 1235
(SELECT c1.CountryID FROM tblCountry c1
ORDER BY c1.CountryName DESC
LIMIT 30) sub1
)
AND e1.CategoryID NOT IN
(
SELECT sub2.CategoryID FROM -- wrapping due due Error code: 1235
(SELECT cat1.CategoryID FROM tblCategory cat1
ORDER BY cat1.CategoryName DESC
LIMIT 15) sub2
)
ORDER BY e1.EventDate
From: | bhilarev |
When: | 26 Oct 17 at 10:23 |
Select EventName,EventDetails,CountryID
From EventInfo
Where CountryId NOT IN
(
Select Top 30 CountryID
From Country
Order By CountryName Desc
)
And CategoryID NOT IN
(
Select Top 15 CategoryID
From Category
Order By CategoryName Desc
)
From: | Zerish |
When: | 23 May 18 at 04:34 |
SELECT EventName,EventDetails
FROM tblCountry
INNER JOIN tblEvent
ON tblCountry.CountryID=tblEvent.CountryID
INNER JOIN tblCategory
ON tblCategory.CategoryID=tblEvent.CategoryID
WHERE tblCountry.CountryID NOT IN
(SELECT TOP 30 tblCountry.CountryID
FROM tblCountry
ORDER BY CountryName DESC)
AND
tblCategory.CategoryID NOT IN
(SELECT TOP 15 tblCategory.CategoryID
FROM tblCategory
ORDER BY tblCategory.CategoryName DESC)
ORDER BY EventName DESC
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.