SQL

Cards (25)

  • What does SQL stand for?
    Structured Query Language
  • What is the purpose of SQL?
    To search database tables for specific data
  • What do records and fields refer to in a database table?
    Rows and columns
  • Which keywords are the most important in SQL?
    SELECT and FROM
  • How do you write a query to retrieve data?
    Use SELECT followed by field names and FROM
  • What does the SELECT keyword do?
    Retrieves specified fields from a database
  • What does the FROM keyword specify?
    The table from which to retrieve data
  • What does the wildcard character '*' do in SQL?
    Returns all fields from a table
  • What is the purpose of the WHERE keyword?
    To specify conditions for returned records
  • How would you filter hotels with a rating greater than 4.1?
    SELECT * FROM hotels WHERE hotelRating > 4.1
  • What do Boolean operators AND and OR do in SQL?
    Make searches more specific
  • Write a SQL query to find hotels with an en-suite bathroom and price under £45.
    SELECT hotelName FROM hotels WHERE bathroom = "En-suite" AND priceInPounds < 45
  • What does the ORDER BY keyword do in SQL?
    Sorts records in ascending or descending order
  • How would you write a query to find hotels with more than 100 rooms, excluding Windy Hotel?
    SELECT hotelName, priceInPounds FROM hotels WHERE rooms > 100 AND hotelName != "Windy Hotel"
  • What is the result of the query SELECT hotelName FROM hotels WHERE rooms > 100 AND hotelName != "Windy Hotel"?
    Returns names of hotels with >100 rooms
  • What is the structure of the viewings table?
    customer, propertyNumber, time
  • How do you join two tables in SQL?
    Using the WHERE clause to match fields
  • Write a SQL query to find addresses and times of viewings with "Helen".
    SELECT properties.address, viewings.time FROM properties, viewings WHERE viewings.propertyNumber = properties.propertyNumber AND customer = "Helen" ORDER BY time ASC
  • What is the result of the query SELECT properties.address, viewings.time FROM properties, viewings WHERE customer = "Helen" ORDER BY time ASC?
    Returns addresses and times for Helen's viewings
  • What is the structure of the properties table?
    propertyNumber, parking, address
  • What does the INSERT INTO statement do?
    Adds new records to a table
  • What are the key components of a SQL query?
    • SELECT: specifies fields to retrieve
    • FROM: specifies the table to search
    • WHERE: filters records based on conditions
    • ORDER BY: sorts records in a specified order
  • How do you filter records in SQL using multiple conditions?
    • Use WHERE to specify conditions
    • Combine conditions with AND or OR
    • Example: WHERE condition1 AND condition2
  • What are the differences between the viewings and properties tables?
    • Viewings: contains customer, propertyNumber, time
    • Properties: contains propertyNumber, parking, address
    • Viewings link to Properties via propertyNumber
  • always write
    SELECT
    FROM
    WHERE