SQL101-Homework Assignment #1 Answer Key

As promised, here are my answers to the first homework assignment.  If you have something different, please get in touch with me so we can discuss the differences in our answers.  There is always more than one way to come to the same result in SQL, but I want to make sure you have the fundamentals. These answers have been updated to work with AdventureWorks on 2008R2.

And now: the answers.
1. What query would show me all the records in example.person?

SELECT * FROM Example.Person

2. What query would show me the first name and last name for all records in Person.Contact?

SELECT
       FirstName
     , LastName
FROM Person.Contact

3. Now, starting from the last query, what query would limit the results to just those people with a last name of Sanchez?

SELECT
       FirstName
     , LastName
FROM Person.Contact
WHERE
     LastName = 'Sanchez'

4. Again, using our query to show us first and last name from Person.contact, limit the results to people with a last name starting with c.

SELECT
       FirstName
     , LastName
FROM Person.Contact
WHERE
     LastName LIKE 'c%'

5. Given there are many rows returned by the query you wrote in question 4, limit the results to 10 rows.

SELECT TOP 10
       FirstName
     , LastName
FROM Person.Contact
WHERE
     LastName LIKE 'c%'

There you go!  The answers to the first homework assignment.

1 Comment on "SQL101-Homework Assignment #1 Answer Key"


Leave a Reply

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