MIN MAX values

Discussion in 'MySQL' started by diesel707, Aug 14, 2007.

  1. #1
    Need help writing a MySQL query for the following in a dreamweaver recordset

    Im trying to Display the MIN MAX values from each ID in T_table

    so for example I have 4 records with the ID of 1 and 4 records with the ID of 2 etc

    P_table
    P_ID
    P_name
    P_image
    --------------
    T_table
    T_ID
    T_number

    Then i would like to match T_table.ID to P_table.ID
    So the Min Max values of T_number will be related to the information on P_table


    Hope this makes sense :eek:
     
    diesel707, Aug 14, 2007 IP
  2. tbarr60

    tbarr60 Notable Member

    Messages:
    3,455
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    210
    #2
    It kinda makes sense.

    I think you need some syntax like:

    SELECT MAX(sale_amt) AS MaxAmount, MIN(sale_amt) AS MinAmount

    If you want related data from another table you will need a JOIN statement so Google "MySQL Join" to see how that works.
     
    tbarr60, Aug 15, 2007 IP
  3. diesel707

    diesel707 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    when i run the test in the recordset it shows the information of both tables linked together, with this query.

    SELECT * FROM T_table,P_table WHERE T_table.prod_id=P_table.prod_id;

    but when i run the repeat region which contains info from both tables it just shows the highest number of all the records for each record. (from P_table)

    If anyone can point me in the right direction

    the following statement, would probably need to be in the mix some where
    MIN(number),MAX(number)

    :confused:
     
    diesel707, Aug 15, 2007 IP
  4. tbarr60

    tbarr60 Notable Member

    Messages:
    3,455
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    210
    #4
    Here's something that is close. It works in SQL Server and should work in MySQL. I leave the join to you.

    SELECT DISTINCT T_id, MAX(T_number) AS Expr1
    FROM dbo.test
    GROUP BY T_id
     
    tbarr60, Aug 15, 2007 IP