AS LIKE

Cards (12)

  • Databases
    A structured collection of data that is organized and stored in a way that allows for efficient retrieval, management, and manipulation of information
  • Structured Query Language (SQL)

    A programming language used for managing data stored in relational databases
  • Renaming fields in SQL output

    1. Use the AS keyword
    2. Give a temporary alternative name to a column or table
  • COUNT(PetID) is not very user-friendly, so we can rename it
  • Alias
    A temporary name given to a table or column, makes it more readable
  • Using AS to generate alternative column or table names

    SELECT ... AS ... FROM ... WHERE ...
  • Renaming fields in SQL

    • SELECT Name AS 'Pet Name' FROM Pet WHERE TYPE = 'Dog'
    • SELECT AVG(age) AS 'Average Age of Pets' FROM Pet WHERE TYPE = 'Dog'
  • LIKE operator

    • Used in a WHERE clause to search for a specified pattern in a column
    • % represents zero, one, or multiple characters
    • _ represents one, single character
  • Using LIKE operator

    • 'Jim Smith' LIKE 'Hello' (FALSE)
    • 'Jim Smith' LIKE 'JiM SmiTh' (TRUE)
    • 'Jim Smith' LIKE '%Smith' (TRUE)
    • 'Jim Smith' LIKE '%im%' (TRUE)
  • Using LIKE operator in SQL
    1. SELECT * FROM Pet WHERE Name LIKE '_oggo'
    2. SELECT * FROM Pet WHERE Name LIKE '_og%'
    3. SELECT * FROM Pet WHERE Name NOT LIKE '_%go'
  • Using LIKE with OR

    • SELECT NAME FROM Pet WHERE (Name LIKE '%s') OR (Name LIKE '%e')
  • Using LIKE with OR and AND
    • SELECT NAME FROM Pet WHERE (Name LIKE '%s' OR Name LIKE '%e') AND (age >= 6)