Need help with SQL statement

Results 1 to 2 of 2

Thread: Need help with SQL statement

  1. #1
    George Jewell Guest

    Default Need help with SQL statement

    I hope someone can help me with this. I need to build a somewhat complex SQL query (complex for me!) Actually, I&#039m not sure if the results I want are possible. Here&#039s the situation: I have an &#039orders&#039 table and an &#039order items&#039 table. Any order can have 1 or more items (or none). What I would like to do, using ASP, is to query the DB to get each order and the items belonging to that order. I would like to display this in a table, in a "grouped" fashion, with the order on one line, then the order items on the next line. After the last order item is displayed, the next line would be the next order. I want to do that for each order. Currently I am querying the order items table for each record in the orders table. This seems very inefficient to me. Is there a way to get this info in one query, and group it in a table like I want? Any help would be appreciated. Thank you.<BR><BR>G. Jewell

  2. #2
    Join Date
    Dec 1969

    Default RE: Need help with SQL statement

    On your SQL statement, join the 2 tables, given that you have an orderID field in both tables...<BR><BR>SELECT o.orderID, oi.item FROM orders o, order items oi WHERE o.orderID = oi.orderID GROUP BY o.orderID<BR><BR>Then this should group the records as you want them. You could then examine the order id while writing out the recordset, and only print it once, when it changes.<BR><BR><BR>HTH<BR><BR>Jerry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts