SQL Coding Reviewer - Lessons 4 to 7

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/38

flashcard set

Earn XP

Description and Tags

This set of flashcards covers SQL basics, functions, advanced queries (joins and subqueries), database structure (DDL), and constraints based on Lessons 4 through 7.

Last updated 1:40 AM on 8/11/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

39 Terms

1
New cards

How do you retrieve all columns from a table named students?

SELECT * FROM students;

2
New cards

How do you display only the student's first name and age from the students table?

SELECT first_name, age FROM students;

3
New cards

How do you filter records to display students whose age is 1818?

SELECT * FROM students WHERE age = 18;

4
New cards

What SQL command retrieves students older than 1818?

SELECT * FROM students WHERE age > 18;

5
New cards

How do you sort data in the students table from smallest to largest age?

SELECT * FROM students ORDER BY age ASC;

6
New cards

How do you sort data in the students table from largest to smallest age?

SELECT * FROM students ORDER BY age DESC;

7
New cards

How do you display students aged 1818 or older and sort them by age in ascending order?

SELECT * FROM students WHERE age >= 18 ORDER BY age ASC;

8
New cards

Which SQL function converts a first_name to all capital letters?

SELECT UPPER(first_name) FROM students;

9
New cards

Which function converts a name to lowercase?

SELECT LOWER(first_name) FROM students;

10
New cards

How do you capitalize the first letter of each word in the first_name column?

SELECT INITCAP(first_name) FROM students;

11
New cards

How do you find the number of characters in a name column?

SELECT LENGTH(first_name) FROM students;

12
New cards

How do you extract 33 characters from the first_name column starting from position 11?

SELECT SUBSTR(first_name, 1, 3) FROM students;

13
New cards

How do you replace the text 'John' with 'Johnny' in the first_name column?

SELECT REPLACE(first_name, 'John', 'Johnny') FROM students;

14
New cards

What is the result of SELECT ROUND(15.678) FROM dual;?

1616

15
New cards

How do you remove decimal places from 15.67815.678 without rounding?

SELECT TRUNC(15.678) FROM dual;

16
New cards

How do you find the remainder of 1010 divided by 33 in Oracle?

SELECT MOD(10, 3) FROM dual;

17
New cards

How do you display the current system date in Oracle?

SELECT SYSDATE FROM dual;

18
New cards

How do you count the total number of records in the students table?

SELECT COUNT(*) FROM students;

19
New cards

Which function is used to calculate the total salary of all employees?

SELECT SUM(salary) FROM employees;

20
New cards

Which function finds the average, highest, and lowest salary respectively?

AVG(salary), MAX(salary), and MIN(salary)

21
New cards

How do you group employees by department_id and count them?

SELECT department_id, COUNT(*) FROM employees GROUP BY department_id;

22
New cards

How do you display only departments that have more than 55 employees?

SELECT department_id, COUNT() FROM employees GROUP BY department_id HAVING COUNT() > 5;

23
New cards

What is the primary difference between WHERE and HAVING?

WHERE filters rows; HAVING filters groups.

24
New cards

How do you join the employees table (e) and departments table (d) on department_id?

SELECT e.first_name, d.department_name FROM employees e JOIN departments d ON e.department_id = d.department_id;

25
New cards

How do you find employees who work in the 'IT' department using a subquery?

SELECT first_name FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE department_name = 'IT');

26
New cards

Which operator do you use when a subquery returns multiple values (MANY)?

IN

27
New cards

How do you find employees whose salary is greater than the average salary using a subquery?

SELECT first_name, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

28
New cards

How do you check if a department has employees using the EXISTS operator?

SELECT d.department_name FROM departments d WHERE EXISTS (SELECT 1 FROM employees e WHERE e.department_id = d.department_id);

29
New cards

How do you add a column named birthday with the DATE data type to the students table?

ALTER TABLE students ADD birthday DATE;

30
New cards

How do you change the data type of the first_name column to VARCHAR2(50)?

ALTER TABLE students MODIFY first_name VARCHAR2(50);

31
New cards

How do you rename the column 'section' to 'class_section' in the students table?

ALTER TABLE students RENAME COLUMN section TO class_section;

32
New cards

How do you remove the birthday column from the students table?

ALTER TABLE students DROP COLUMN birthday;

33
New cards

How do you rename the table 'students' to 'shs_students'?

RENAME students TO shs_students;

34
New cards

What is the difference between DROP TABLE and TRUNCATE TABLE?

DROP TABLE deletes the entire table and its data; TRUNCATE TABLE empties the table but keeps the structure.

35
New cards

How do you delete a specific record where the student_id is 101101?

DELETE FROM students WHERE student_id = 101;

36
New cards

How do you define a column as a primary key when creating a table?

student_id NUMBER PRIMARY KEY

37
New cards

Which constraint prevents duplicate values in a column like email?

UNIQUE

38
New cards

How do you create a constraint to ensure age is at least 1818?

CHECK (age >= 18)

39
New cards

Which constraint is used to connect a column in one table to the primary key of another table?

FOREIGN KEY