Dec 4, 2006

Obvious SQL Tip #2

Thinking in sets:
The thought process that goes into set- based programming is slightly different from writing procedural code.

Say, I have 2 tables -one holding order header information and the other holding the details of the products ordered. I want to get the items ordered for all the orders:

  • The procedural way of looking at it is "for each order in the orders table get the order details from the [order details] table".
  • In DB terms, its "for all orders in the orders table get the order details from the [order details] table".