20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3<br />

Exercise 1 Solution<br />

First of all, you need to consider which columns and from what table or tables you need to get the<br />

answer. In this case, you get answers from the MemberDetails table and the Street, City, State, and<br />

ZipCode columns. Because you already know the MemberId (13), all you need to do is filter results by<br />

adding a WHERE clause that contains only rows where MemberId equals 13:<br />

SELECT Street, City, State, ZipCode<br />

FROM MemberDetails<br />

WHERE MemberId = 13;<br />

Executing this query provides the following results:<br />

Street City State ZipCode<br />

Winding Road Big City Mega State 34512<br />

Exercise 2 Solution<br />

You need to find the names of the members, so the FirstName and LastName columns from the<br />

MemberDetails table need to be selected. Now you need to add a WHERE clause with a condition that<br />

checks for last names starting with J. The LIKE operator will do this:<br />

SELECT FirstName, LastName<br />

FROM MemberDetails<br />

WHERE LastName LIKE ‘J%’;<br />

The percent sign (%) means one or more of any character. Note that in MS Access you need to use an<br />

asterisk (*) instead of the percent sign (%).<br />

Executing the final query provides the following results:<br />

FirstName LastName<br />

John Jackson<br />

John Jones<br />

Jenny Jones<br />

Jack Johnson<br />

Exercise Answers<br />

373

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!