Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order by no. of occurrances 1

Status
Not open for further replies.

johnv20

Programmer
Joined
Sep 26, 2001
Messages
292
Location
US
Hi, I need to count the no of times an entry appears in a field in 1 table and order a seperate table by this count where the 2 tables are linked by a different field. Does anyone have an idea how this can be done ?
 
Here is one that sorts by the number of line items associated with a purchase order, and grabs some stuff from the purchase order, too. Modify and have fun:

Code:
SELECT dbo.tblPOLineItem.PONumber, Count(dbo.tblPOLineItem.PONumber) AS Total,
 	tblPurchaseOrders.RequestDate, tblPurchaseOrders.CostCenter
	FROM dbo.tblPOLineItem INNER Join dbo.tblPurchaseOrders 
		ON tblPOLineItem.PONumber = tblPurchaseOrders.PONumber
	GROUP BY dbo.tblPOLineItem.PONumber, tblPurchaseOrders.CostCenter, tblPurchaseOrders.RequestDate
	ORDER BY Total DESC

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top