CS Grade 9-12

CS: SQL: SELECT, WHERE, JOIN

Querying tables, filtering rows, and combining data

View Answer Key
Name:
Date:
Score: / 12

Querying tables, filtering rows, and combining data

CS - Grade 9-12

Instructions: Read each problem carefully. Write the SQL query or explain the result. Use clear table and column names from the problem.
  1. 1

    A table named Students has columns student_id, first_name, last_name, and grade_level. Write a SQL query that shows only the first_name and last_name columns for every student.

  2. 2

    A table named Books has columns book_id, title, author, and pages. Write a SQL query that shows all columns for books with more than 300 pages.

  3. 3

    A table named Movies has columns movie_id, title, rating, and release_year. Write a SQL query that shows the title and release_year of movies with a rating equal to 'PG-13'.

  4. 4

    Use this table: Employees(employee_id, first_name, last_name, department, salary). Write a SQL query that shows all employees in the 'Sales' department who have a salary greater than 50000.

  5. 5

    A table named Products has columns product_id, product_name, category, and price. Write a SQL query that shows product_name and price for products in the 'Electronics' category with a price less than or equal to 100.

  6. 6
    Two blank database tables connected by matching highlighted key columns.

    Two tables are shown. Customers has columns customer_id, name, and city. Orders has columns order_id, customer_id, and order_date. Write a SQL query that shows each order_id with the customer's name.

  7. 7
    Two blank tables show a shared key column linking multiple records to another table.

    Two tables are shown. Authors has columns author_id and author_name. Books has columns book_id, title, and author_id. Write a SQL query that shows each book title with its author_name.

  8. 8
    A filtered row in one blank enrollment table links to a matching student row in another table.

    Use these tables: Students(student_id, name) and Enrollments(enrollment_id, student_id, course_name). Write a SQL query that shows the names of students enrolled in 'Biology'.

  9. 9
    Blank player and team tables connected by a shared key column.

    Use these tables: Teams(team_id, team_name) and Players(player_id, player_name, team_id). Write a SQL query that shows player_name and team_name for every player.

  10. 10

    A table named Sales has columns sale_id, item_name, quantity, and store_location. Write a SQL query that shows item_name and quantity for sales where store_location is 'Denver' or 'Austin'.

  11. 11
    A highlighted teacher row in one blank table connects to matching course rows in another table.

    Use these tables: Courses(course_id, course_name, teacher_id) and Teachers(teacher_id, teacher_name). Write a SQL query that shows course_name and teacher_name only for courses taught by 'Ms. Rivera'.

  12. 12

    Explain the difference between SELECT, WHERE, and JOIN in SQL. Use one sentence for each keyword.

LivePhysics™.com CS - Grade 9-12

More CS Worksheets

See all CS worksheets

More Grade 9-12 Worksheets

See all Grade 9-12 worksheets