Need help merging Queries?

equinox's Avatar, Join Date: Aug 2007
Newbie Member
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?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
UNION can be one of the options for you.
jwshepherd's Avatar, Join Date: Aug 2007
Team Leader
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
equinox's Avatar, Join Date: Aug 2007
Newbie Member
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
jwshepherd's Avatar, Join Date: Aug 2007
Team Leader
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;