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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do this with no subquery??

Status
Not open for further replies.

imstillatwork

IS-IT--Management
Sep 26, 2001
1,605
US
Can I get a recordset like this with no subquery? My host (crystaltech is not on 4.1 and I'm getting out of MS Access)

Code:
	SELECT 
		OI.Item_ID
		,OI.Order_Item_Name
		,OI.Order_Item_Quantity
		,Order_Item_Number
		,Order_Item_Price
		,(SELECT SUM(OI1.Order_Item_Quantity) FROM Order_Items AS OI1 WHERE OI1.Order_Item_number = OI.Order_Item_number) AS qty
	FROM 
		Order_Items AS OI
		LEFT JOIN Order_Master AS OM
		ON OM.Order_Invoice = OI.Order_Invoice
		
	ORDER BY 	
		Order_Item_Name

 
i didn't test it but it should work

Code:
 SELECT
        OI.Item_ID
        ,OI.Order_Item_Name
        ,OI.Order_Item_Quantity
        ,Order_Item_Number
        ,Order_Item_Price
        ,SUM(OI1.Order_Item_Quantity) AS Qty
    FROM
        Order_Items AS OI
        LEFT JOIN Order_Master AS OM
        ON OM.Order_Invoice = OI.Order_Invoice
        LEFT JOIN Order_Items AS OI1 WHERE OI1.Order_Item_number = OI.Order_Item_number
    GROUP BY OI.Item_ID
    ORDER BY
        Order_Item_Name

gry online
 
Ahhh. I'l play with that as soon as I can... interesting.

Thanks!!

 
with a few corrections and the new table / field names it is working great. thats for the jump start!

Code:
	 SELECT
        op.Order_product_name
        ,op.Order_product_qty
        ,op.Order_product_number
        ,op.Order_product_price
        ,SUM(op1.order_product_qty) AS sumqty
    FROM
        (nwcs_order_products AS op
		
     	LEFT JOIN nwcs_orders AS o
        ON o.order_id = op.order_id)
        
		LEFT JOIN nwcs_order_products AS op1 
		ON op1.order_product_id = op.order_product_id
    GROUP BY op.order_product_number
    ORDER BY
        sumqty

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top