Skip to main content
Participant
January 29, 2007
Question

Q of Q Question

  • January 29, 2007
  • 1 reply
  • 185 views
Hi,

I am trying to consolidate my code so that I can output the results using one query instead of two, but I can't seem to make it work.

If you look at my code you will see the following.
1. The first query gets all the order info from the "Orders" and "OrdersItems" tables.
2. The second query (Q of Q) totals the order info by month and year.
3. The third query (Q of Q) gets a grand total for each year.

This currently works fine if I output the second and third queries separately.
However, I would like to combine them into one query so that I can have better control over how I group the data.

Can this be done?

Thanks in advance for any help offered.

Steve


    This topic has been closed for replies.

    1 reply

    January 30, 2007
    Yes, you can merge the queries with a fourth QofQ that unions the three original queries. However, depending on what DB you are using, there is a better way.

    For example, in MS SQL, you would use "with rollup" or "with cube" to have the DB automatically return the monthly, yearly, and grand totals and return everything on one initial query.

    Similar functionality exists in Oracle, DB2, MySQL5, etc.

    The exact syntax will vary so look it up or report that info here.