Results 1 to 4 of 4

Thread: T-sql

  1. #1
    Join Date
    Mar 2006
    Posts
    14

    T-sql

    how I can write query which can write all the coloumns who ordered max quantity

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Do you have any sample data and what you like to see?

  3. #3
    Join Date
    Mar 2006
    Posts
    14
    Quote Originally Posted by rmiao
    Do you have any sample data and what you like to see?
    hi rmiao I have a table Name: Order Details

    coloumn: orderid, productid, unitprice, quantity, discount
    i need all the coloumns to be printed which corresponds to max quantity

  4. #4
    Join Date
    Dec 2004
    Posts
    502
    You need to be a little clearer about what you want, and it would help to provide actual data. However, I'm going to take a guess at what you want:

    SELECT * FROM OrderDetails
    WHERE quantity = (SELECT MAX(quantity) FROM OrderDetails)

    Or, for example, to see all the data corresponding to each OrderId's max quantity:

    SELECT * FROM OrderDetails AS A
    JOIN (SELECT OrderId, MAX(quantity) AS MaxQuantity FROM OrderDetails GROUP BY OrderID) AS B
    ON A.OrderId = B.OrderId AND A.quantity = B.MaxQuantity

    etc.

Posting Permissions

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