$q = $dbh->prepare('
select * from (
select
+ gametime as sort_gametime,
to_char(gametime, \'IYYY-MM-DD HH24:MI\') as gametime,
\'Double\' as type,
team1_username1 || \' / \' || team1_username2 as username1,
and re.team2_username2=ra4.username
union all
select
+ gametime as sort_gametime,
to_char(gametime, \'IYYY-MM-DD HH24:MI\') as gametime,
\'Single\' as type,
username1,
on re.gametime=ra2.ratetime
and re.username2=ra2.username
) t1
-order by gametime desc limit 10');
+order by sort_gametime desc limit 10');
$q->execute();
while (my $ref = $q->fetchrow_hashref) {
if (defined($ref->{'diff2'})) {