none
Can I write query like this? RRS feed

  • Question

  • hi, guys

    Can I write query like this:
    I need to get the amount of stores that have @PID inventory less than 2
    select count(*) from
    (
         select StoreID, sum(Inventory) as Inv from products where productID = @PID group by storeID
    ) StoreInv where StoreInv.Inv <= 2

    thanks.

    Friday, January 20, 2006 8:23 PM

Answers

  • Yes, you can. Your query is valid so long as you use an alias name for the resultset generated by a nested query. Following is a very simple example to get the point across quickly:

    Select Count(*) From (Select State from Authors) A

    Friday, January 20, 2006 9:42 PM