Chhetri AcademyGCSE & A level Paper Builder

SQL

OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Programming fundamentals › Additional programming techniques

Practise SQL. 12 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.

Build a paper on this topic

▶ Watch videos on SQL (Craig 'n' Dave OCR on YouTube) · Practise all of Additional programming techniques

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy4 marks
A sports club stores details of its members in a database table called Members. {table} shows the table.
[object Object]
(a) Complete the SQL statement so that it displays the first name and surname of every member who lives in Hilltown.
SELECT FirstName, Surname
.............. Members
.............. Town = "Hilltown"
[2]
(b) State the purpose of the * in SELECT * FROM Members.[1]
(c) State the first names returned by the completed statement.[1]
Show the answer and mark scheme
(a)
  • FROM
  • WHERE
(b)
  • it selects / displays all the fields (of each record)
(c) Answer: Asha, Priya, Omar
  • Asha, Priya and Omar (and no others)
Question 2Medium5 marks
A cinema stores details of films in a table called Films. {table} shows the table.
[object Object]
(a) Write an SQL statement to display the title and running time (Minutes) of every comedy film that is shorter than 100 minutes.[3]
(b) State the results that your statement would return.[2]
Show the answer and mark scheme
(a) Answer:
SELECT Title, Minutes
FROM Films
WHERE Genre = 'Comedy' AND Minutes < 100
  • SELECT Title, Minutes
  • FROM Films
  • WHERE Genre = 'Comedy' AND Minutes < 100
(b)
  • Lost in Leeds, 94
  • Pet Detectives, 87 (and no other records)
Question 3Hard7 marks
A car dealer stores details of cars for sale in a table called Cars with the fields Reg, Make, Colour, Year, Mileage and Price.
(a) Write an SQL statement to display all the fields for cars made from 2018 to 2021 inclusive.[3]
(b) Write an SQL statement to display the registration and price of every car that is red or blue and has a mileage of less than 40 000.[4]
Show the answer and mark scheme
(a) Answer:
SELECT * FROM Cars
WHERE Year >= 2018 AND Year <= 2021
  • SELECT * FROM Cars
  • WHERE Year >= 2018
  • AND Year <= 2021
(b) Answer:
SELECT Reg, Price FROM Cars
WHERE (Colour = 'Red' OR Colour = 'Blue')
AND Mileage < 40000
  • SELECT Reg, Price FROM Cars
  • Colour = 'Red' OR Colour = 'Blue'
  • AND Mileage < 40000
  • brackets around the OR condition so that the mileage condition applies to both colours

Related subtopics

Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.

Book a free trial