Sams Teach Yourself SQL in 24 Hours
- Table of Contents
- Copyright
- About the Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- Part I: A SQL Concepts Overview
- Hour 1. Welcome to the World of SQL
- Part II: Building Your Database
- Hour 2. Defining Data Structures
- Hour 3. Managing Database Objects
- Hour 4. The Normalization Process
- Hour 5. Manipulating Data
- Hour 6. Managing Database Transactions
- Part III: Getting Effective Results from Queries
- Hour 7. Introduction to the Database Query
- Hour 8. Using Operators to Categorize Data
- Hour 9. Summarizing Data Results from a Query
- Hour 10. Sorting and Grouping Data
- Hour 11. Restructuring the Appearance of Data
- Hour 12. Understanding Dates and Times
- Part IV: Building Sophisticated Database Queries
- Hour 13. Joining Tables in Queries
- Hour 14. Using Subqueries to Define Unknown Data
- Hour 15. Combining Multiple Queries into One
- Part V: SQL Performance Tuning
- Hour 16. Using Indexes to Improve Performance
- Hour 17. Improving Database Performance
- Part VI: Using SQL to Manage Users and Security
- Hour 18. Managing Database Users
- Hour 19. Managing Database Security
- Part VII: Summarized Data Structures
- Hour 20. Creating and Using Views and Synonyms
- Hour 21. Working with the System Catalog
- Part VIII: Applying SQL Fundamentals in Today's World
- Hour 22. Advanced SQL Topics
- Hour 23. Extending SQL to the Enterprise, the Internet, and the Intranet
- Hour 24. Extensions to Standard SQL
- Part IX: Appendixes
- Appendix A. Common SQL Commands
- Appendix B. Using MySQL for Exercises
- Appendix C. Answers to Quizzes and Exercises
- Appendix D. CREATE TABLE Statements for Book Examples
- Appendix E. INSERT Statements for Data in Book Examples
- Appendix F. Glossary
- Appendix G. Bonus Exercises
Workshop
The following workshop is composed of a series of quiz questions and practical exercises. The quiz questions are designed to test your overall understanding of the current material. The practical exercises are intended to afford you the opportunity to apply the concepts discussed during the current hour, as well as build upon the knowledge acquired in previous hours of study. Please take time to complete the quiz questions and exercises before continuing. Refer to Appendix C,"Answers to Quizzes and Exercises," for answers.
Quiz
-
True or false: Both conditions when using the OR operator must be TRUE.
-
True or false: All specified values must match when using the IN operator.
-
True or false: The AND operator can be used in the SELECT and the WHERE clauses.
-
What, if anything, is wrong with the following SELECT statements?
-
SELECT SALARY FROM EMPLOYEE_PAY_TBL WHERE SALARY BETWEEN 20000, 30000
-
SELECT SALARY + DATE_HIRE FROM EMPLOYEE_PAY_TBL
-
SELECT SALARY, BONUS FROM EMPLOYEE_PAY_TBL WHERE DATE_HIRE BETWEEN 1999-09-22 AND 1999-11-23 AND POSITION = 'SALES' OR POSITION = 'MARKETING' AND EMPLOYEE_ID LIKE '%55%
-
Exercises
-
Using the following CUSTOMER_TBL:
DESCRIBE CUSTOMER_TBL; Name Null? Type -------------------------------- -------- ------------ CUST_ID NOT NULL VARCHAR (10) CUST_NAME NOT NULL VARCHAR (30) CUST_ADDRESS NOT NULL VARCHAR (20) CUST_CITY NOT NULL VARCHAR (12) CUST_STATE NOT NULL VARCHAR(2) CUST_ZIP NOT NULL VARCHAR(5) CUST_PHONE VARCHAR (10) CUST_FAX VARCHAR(10)Write a SELECT statement that returns customer IDs and customer names (alpha order) for customers who live in Indiana, Ohio, Michigan, and Illinois, and whose names begin with the letters A or B.
-
Using the following PRODUCTS_TBL:
DESCRIBE PRODUCTS_TBL Name Null? Type ------------------------------- --------------------- PROD_ID NOT NULL VARCHAR (10) PROD_DESC NOT NULL VARCHAR (25) COST NOT NULL DECIMAL(6,2)Write a SELECT statement that returns the product ID, PROD_DESC, and the product cost. Limit the product cost to range from $1.00 and $12.50.
-
Assuming that you used the BETWEEN operator in exercise 2 above, rewrite your SQL statement to achieve the same results using different operators. If you did not use the BETWEEN operator, then do so now.
-
Write a SELECT statement that returns products that are either less than 1.00 or greater than 12.50. There are two ways to achieve the same results.
-
Write a SELECT statement that returns the following information from PRODUCTS_TBL: product description, product cost, and 5% sales tax for each product. List the products in order from most to least expensive.
-
Write a SELECT statement that returns the following information from PRODUCTS_TBL: product description, product cost, and 5% sales tax for each product, and total cost with sales tax. List the products in order from most to least expensive. There are two ways to achieve the same results. Try both.
Hour 9. Summarizing Data Results from a Query | Next Section

Account Sign In
View your cart