By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
By the end of this topic, students will be able to:
A database is a collection of organized data that can be efficiently accessed, managed, and updated. SQL (Structured Query Language) is a standard language for managing relational databases. It allows users to store, manipulate, and retrieve data.
A database consists of:
SQL has several key concepts:
SQL syntax is case-insensitive, but it's common to use uppercase for keywords and lowercase for field names.
SQL supports various data types, including:
Suppose we have a table called 'students' with fields 'name', 'age', and 'grade'. We want to retrieve the names of all students with a grade above 80.
SELECT name FROM students WHERE grade > 80;
We want to retrieve the names of all students who live in 'London' and have an age above 16.
SELECT name FROM students WHERE city = 'London' AND age > 16;
We want to retrieve the names of all students sorted in ascending order by age.
SELECT name FROM students ORDER BY age ASC;
What is the purpose of the SELECT statement in SQL? A) To insert new data into a table B) To delete data from a table C) To retrieve data from a table D) To update data in a table
Correct answer: C) To retrieve data from a table Why the distractors fail: A and B are incorrect because SELECT is used for retrieval, not insertion or deletion. D is incorrect because UPDATE is used for modifying existing data.
What is the difference between the AND and OR operators in SQL? A) AND returns true if both conditions are true, while OR returns true if either condition is true B) AND returns true if either condition is true, while OR returns true if both conditions are true C) AND returns false if either condition is false, while OR returns false if both conditions are false D) AND returns true if both conditions are false, while OR returns true if either condition is false
Correct answer: A) AND returns true if both conditions are true, while OR returns true if either condition is true Why the distractors fail: B and C are incorrect because AND returns true if both conditions are true, while OR returns true if either condition is true. D is incorrect because AND returns true if both conditions are true, while OR returns true if either condition is true.
What is the correct syntax for sorting data in ascending order using the ORDER BY clause? A) ORDER BY age DESC B) ORDER BY age ASC C) ORDER BY age D) ORDER BY age IN ASC
Correct answer: B) ORDER BY age ASC Why the distractors fail: A is incorrect because DESC is used for descending order, not ascending. C is incorrect because the ORDER BY clause requires a direction (ASC or DESC). D is incorrect because IN is not a valid direction for the ORDER BY clause.
What is the purpose of the WHERE clause in SQL? A) To specify the table(s) to retrieve data from B) To filter data based on conditions C) To sort data in ascending or descending order D) To insert new data into a table
Correct answer: B) To filter data based on conditions Why the distractors fail: A is incorrect because FROM is used to specify the table(s) to retrieve data from. C is incorrect because ORDER BY is used to sort data. D is incorrect because INSERT is used to insert new data into a table.
What is the correct syntax for retrieving the names of all students with a grade above 80? A) SELECT name FROM students WHERE grade > 80 B) SELECT name FROM students WHERE grade = 80 C) SELECT name FROM students WHERE grade < 80 D) SELECT name FROM students WHERE grade >= 80
Correct answer: A) SELECT name FROM students WHERE grade > 80 Why the distractors fail: B is incorrect because it retrieves students with a grade of exactly 80, not above 80. C is incorrect because it retrieves students with a grade below 80, not above 80. D is incorrect because it retrieves students with a grade of 80 or above, but the question asks for students with a grade above 80.
Explain the difference between the AND and OR operators in SQL. Provide an example of each operator in use.
Write a SQL query to retrieve the names of all students who live in 'London' and have an age above 16.
What is the purpose of the ORDER BY clause in SQL? Provide an example of using the ORDER BY clause to sort data in ascending order.
Explain the concept of a database and its purpose in computer systems. Provide an example of a simple database schema.
Write a SQL query to retrieve the names of all students sorted in descending order by age.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.