Need help with SQL statement!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    Need help with SQL statement!

    I am having difficulty writing a SQL statement and I was wondering if one of
    you gurus could help me. I have a table that has three fields: InvoiceID,
    Item, ItemPrice. Each InvoiceID is associated with one or more Items. I am
    trying to write a SQL statement that returns the record (all three fields)
    for the least expensive item for each invoice (so the total number of
    records returned will be equal to the total number of unique Invoice IDs.
    How would I write this SQL statement?



    Thank you,



    Alex


  • Leader

    #2
    Re: Need help with SQL statement!

    "Alex" <sh2222@yahoo.c omwrote in message news:<_5lVa.117 527$TJ.6968703@ twister.austin. rr.com>...
    I am having difficulty writing a SQL statement and I was wondering if one of
    you gurus could help me. I have a table that has three fields: InvoiceID,
    Item, ItemPrice. Each InvoiceID is associated with one or more Items. I am
    trying to write a SQL statement that returns the record (all three fields)
    for the least expensive item for each invoice (so the total number of
    records returned will be equal to the total number of unique Invoice IDs.
    How would I write this SQL statement?
    >
    >
    >
    Thank you,
    >
    >
    >
    Alex

    Hi,
    I think you should try with Group by clauseand MIN function. it might help you.

    Thanks
    Hoque

    Comment

    • Alex

      #3
      Re: Need help with SQL statement!

      Thank you all for your help, particularly Mike MacSween's.

      "Alex" <sh2222@yahoo.c omwrote in message
      news:_5lVa.1175 27$TJ.6968703@t wister.austin.r r.com...
      I am having difficulty writing a SQL statement and I was wondering if one
      of
      you gurus could help me. I have a table that has three fields: InvoiceID,
      Item, ItemPrice. Each InvoiceID is associated with one or more Items. I am
      trying to write a SQL statement that returns the record (all three fields)
      for the least expensive item for each invoice (so the total number of
      records returned will be equal to the total number of unique Invoice IDs.
      How would I write this SQL statement?
      >
      >
      >
      Thank you,
      >
      >
      >
      Alex
      >
      >

      Comment

      Working...