T-SQL Tutor Project - 01 Nov 2001

As a regular part of the T-SQL Tutor column, I include a downloadable commented script file online that you can use to test the syntax I show in the article. Additionally, each article includes some homework to help you polish your T-SQL skills and to reinforce the concepts I cover. Here's this month's homework, which uses the TSQLTutorJoins database we created in "Joins 101," October 2001.

  1. Write a query to answer the questions, What categories of products does the company sell, and what products are in each category? List all category and product names. Does this query differ from an inner join between Category and Products?
  2. Write a query to list all customers in the order in which they placed an order. For customers who haven't placed an order, use the ISNULL() function to replace the OrderDate with the string "Not yet placed an order."
  3. Write a query to answer the questions, What's the highest-selling product by individual order quantity sold, and which products have never been sold? Could you write this query another way to produce a more succinct (think aggregated) resultset?
  4. This one is a trick question. Review the following two batches and try to answer the following questions before executing the batches: Will both batches execute, or will one or both generate a syntax error?
SELECT * FROM pubs.dbo.authors WHERE au_lname = 'O''Leary'
SELECT * FROM pubs.dbo.authors

Finally, try executing these batches. Do they both behave the way you expected? Do you know why or why not? The answer is in this article; check the online homework file if you still need help.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.