Thread: nested queries
View Single Post
  #1 (permalink)  
Old 07-22-2008, 02:02 PM
elle39 elle39 is offline
Junior Member
 
Join Date: Jul 2008
Posts: 2
elle39 is on a distinguished road
Unhappy ANY dialect question:

nested queries


I am using SQL Server 2005 don't which dialect that would be SQL 92 I am guessing !

How can I get:

1) only the Top 2 highest InvoiceTotal rows for each VENDOR in each STATE.

2) the VENDORNAMES that have supplied ONLY the highest number of Invoices for each state.


For the first query, I know this is wrong but what should i be doing??
[sql]
Select top 2 Invoicetotals, vendorname, vendorstate
from vendors join invoices on vendorID
Group by vendorstate, Vendorname
Order by InvoiceTotal DESC
[/sql]
For the second query, I didn't quite get it:
[sql]
Select vendorname, vendorstate, count(*) as InvoiceQty
from vendors join invoices on vendorID
Group by VendorState, VendorName
Order by InvoiceTotal DESC
[/sql]
Help !
Reply With Quote

ANSWER(S):