Note:  The Questions are Here!

Question #1

Find all Employees that have marketing in their title

SELECT NationalIDNumber,
       JobTitle
From   HumanResources.Employee
Where  JobTitle like '%Marketing%'

Question #2

Select all addresses that are on drives.

SELECT AddressID,
       AddressLine1,
       City
 FROM  Person.Address
WHERE  AddressLine1 LIKE '%Dr.'
       OR Addressline1 LIKE '%Drive'

Question #3

Select all products whose product number’s numeric portion starts with 7.  Hint – The product number’s format is AA-9999

SELECT ProductID,
       Name,
       ProductNumber
FROM   Production.Product
WHERE  ProductNumber LIKE '__-7___'
One response to “Answers To Exercises: Pattern Matching with SQL”
  1. Tyler

    Hi, Kris! Thanks for this great resource! On #2, I noticed that some addresses do not have a ‘.’ at the end of ‘DR’.

    Example (AdventureWorks2012): AddressID (199, 12869, 12497)

    My SQL:
    SELECT a.AddressID,
    a.AddressLine1
    FROM Person.Address a
    WHERE (a.AddressLine1 LIKE ‘%DRIVE’
    OR a.AddressLine1 LIKE ‘% DR%’) — TO ACCOUNT FOR ‘DR’ & ‘DR.’

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.