Hello,
I have 3 tables:
Code:
t_user t_request t_cycle
- user_id - req_id - cycle_id
- columnA - user_id - req_id
- columnB - columnA - time
- columnB - columnA
Every
t_user has one or more
t_requests. Every
t_request has one or more
t_cycles.
I need a query that displays the
t_user's
t_request having the maximum
t_cycle.time. Here is an example:
Code:
SELECT t_user.user_id, max (t_cycle.time)
FROM t_user
INNER JOIN t_request ON t_user.user_id = t_request.user_id
INNER JOIN t_cycle ON t_request.req_id = t_cycle.req_id
group by t_user.user_id
This query is good but I also want to display also the corresponding
t_request fields and
t_cycle fields. How can I do that?
IMPORTANT:
the solution must not use a subquery that acts like a separate table (derived tables) like:
SELECT ... FROM ...
INNER JOIN ( SELECT ... FROM ...) AS derivedtable ON derivedtable.id = ....
The query can use correlated subqueries.
many thanks