Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MySQL (http://www.go4expert.com/forums/mysql-forum/)
-   -   Need help merging Queries? (http://www.go4expert.com/forums/help-merging-queries-t5910/)

equinox 17Aug2007 18:31

Need help merging Queries?
 
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 18Aug2007 08:17

Re: Need help merging Queries?
 
UNION can be one of the options for you.

jwshepherd 18Aug2007 11:55

Re: Need help merging Queries?
 
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 18Aug2007 22:42

Re: Need help merging Queries?
 
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 20Aug2007 09:06

Re: Need help merging Queries?
 
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;



All times are GMT +5.5. The time now is 07:18.