PUB_UL
asked on
PHP/MySql - INNER JOIN from another query
Hi!
I would like to know how i could achieve a query with the result of another query.. here is my example:
$sql = "SELECT tblranking.IdMembre, Max(tblranking.myDate) AS MaxOfmydate FROM tblranking WHERE Type='DOUBLE' GROUP BY tblranking.IdMembre";
$result = SQL_Query($sql);
$sql2 = "SELECT tblranking.IdRanking, tblranking.IdMembre, tblranking.myDate, tblranking.Points FROM tblranking INNER JOIN $result ON (tblranking.IdMembre = $result["IdMembre"]) AND (tblranking.myDate = $result["MaxDemydate"]) ORDER BY Points DESC";
$result2 = SQL_Query($sql2);
my first query get the ranking up-to-date and the second get the points each member get and i sort it to get the one who has the more points.
The problem is that i don't know how to make the INNER JOIN $result ON ... i know result is an array, but is there a way to make it work?
Oh and if you happen to know how i can test it in PhpMyAdmin, it would be awesome!
It's gonna help me alot for future joins using MySql.
Thanks in advance.
I would like to know how i could achieve a query with the result of another query.. here is my example:
$sql = "SELECT tblranking.IdMembre, Max(tblranking.myDate) AS MaxOfmydate FROM tblranking WHERE Type='DOUBLE' GROUP BY tblranking.IdMembre";
$result = SQL_Query($sql);
$sql2 = "SELECT tblranking.IdRanking, tblranking.IdMembre, tblranking.myDate, tblranking.Points FROM tblranking INNER JOIN $result ON (tblranking.IdMembre = $result["IdMembre"]) AND (tblranking.myDate = $result["MaxDemydate"]) ORDER BY Points DESC";
$result2 = SQL_Query($sql2);
my first query get the ranking up-to-date and the second get the points each member get and i sort it to get the one who has the more points.
The problem is that i don't know how to make the INNER JOIN $result ON ... i know result is an array, but is there a way to make it work?
Oh and if you happen to know how i can test it in PhpMyAdmin, it would be awesome!
It's gonna help me alot for future joins using MySql.
Thanks in advance.
here is an extract from a mysql manual:
Note that in versions before Version 3.23.17, the INNER JOIN didn't take a join_condition!
so are you using the version before that?
temporo
Note that in versions before Version 3.23.17, the INNER JOIN didn't take a join_condition!
so are you using the version before that?
temporo
ASKER
I would prefer to know how i could do it using two queries because i'm gonna work on a stats thing and i know i'm gonna need to do similar queries...
I thought of your suggestion and it would work, but it ain't what i am looking for.
Thanks for you help, still a good suggestion :)
I thought of your suggestion and it would work, but it ain't what i am looking for.
Thanks for you help, still a good suggestion :)
ASKER
I can do a INNER JOIN, but it's from the result of another query, not another table. That's the problem.
I could make a temporary table too using a SELECT... INTO, but i wanna know if i could make it work using the way i showed above.
Maybe it ain't possible, but if it is, i assume there is someone out there who could help me out with it.
Thanks again!
I could make a temporary table too using a SELECT... INTO, but i wanna know if i could make it work using the way i showed above.
Maybe it ain't possible, but if it is, i assume there is someone out there who could help me out with it.
Thanks again!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then use a function with loops to sort out the rank of each of the member depending on the number of points.