1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help merging Queries?

Discussion in 'MySQL' started by equinox, Aug 17, 2007.

  1. equinox

    equinox New Member

    Joined:
    Aug 17, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I have 2 tables... t_table and p_table

    I want the Min Max values in p_table to relate to the records in t_table

    SELECT *
    FROM t_table
    -----------
    SELECT p_id, MIN(total),MAX(total)
    FROM p_table
    GROUP BY p_id

    How could i merge these queries together....or is there another way?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    UNION can be one of the options for you.
     
  3. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    This sis sudo code, because I don't know what on the t_table you are wanting to relate.
    Code:
    SELECT *
    FROM t_table 
    SELECT t_table.*,p_table.p_id, p_table.MIN(total),p_table.MAX(total)
    FROM p_table,t_table
    GROUP BY p_id 
     
  4. equinox

    equinox New Member

    Joined:
    Aug 17, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    jwshepherd ,

    im trying to relate p_table.p_id to t_table.p_id
    so p_table.total will match up against the records in t_table
     
  5. jwshepherd

    jwshepherd New Member

    Joined:
    Aug 13, 2007
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    VP Technology Corporation
    Location:
    Texas
    Home Page:
    Code:
    SELECT t_table.t_id, t_table.p_id, Min(p_table.total) AS MinOftotal, Max(p_table.total) AS MaxOftotal
    FROM p_table INNER JOIN t_table ON p_table.p_id = t_table.p_id
    GROUP BY t_table.t_id, t_table.p_id
    WITH OWNERACCESS OPTION;
    
     

Share This Page