Indeed you can simply write the three queries one after another.
There are several ways of doing query3 with data from query2.
The simplest way I guess would be to start query2,
and leave it open.
Then you can loop through it's results, and perform query 3 for every result in the output of query 2. In pseudo code:
$result1=do_query_1;
$result2=do_query_2(with data from $result1);
while(fetch_row($result2))
{
$result3=do_query_3(with data from $result2;
process data from $result3;
};