I know that question doesn’t make much sense, but here goes:
Times Table
Authority | Time
-------------------------------------
animuson@forums | 45.6758
132075829385895 | 49.7869
qykumsoy@forums | 44.45
439854390263565 | 50.761
user@forums | 44.9
another@auth | 46.123
bingo@nameo | 47.4392
So let me explain this. By default, if you have not linked your account to the authority you use, it just stores times as the authority, but if you link your account, it stores your ID number instead. I want the people with ID numbers to have precedence, so they’ll appear over someone who is not linked, but still in order. So for this sample of data, when choosing the top 5, it would output these results:
Authority | Time
-------------------------------------
qykumsoy@forums | 44.45
user@forums | 44.9
animuson@forums | 45.6758
132075829385895 | 49.7869
439854390263565 | 50.761
-------------------------------------
Ignoring These:
another@auth | 46.123
bingo@nameo | 47.4392
Even though those two users had better times, they got knocked off because they’re not linked, the linked accounts got pushed up, but the top 5 still remained in order of their times. It is safe to assume that an ‘@’ symbol being present within the Authority means that it is an unlinked account. It will always appear in an unlinked authority value and a linked account will always be pure numbers. Any ideas on how to do this in one query?
The current query I use which simply selects the top 5 without thinking:
SELECT * FROM `tronner_times` WHERE `mid` = '{$map['mid']}' ORDER BY `time` + 0 LIMIT 5
This is the first solution that comes to mind. I’m not sure if it can be optimized further, but you may want to try the following:
Test case:
Result:
We are ordering twice, because the derived table returns the rows without the
@sign at the very top. The expressionINSTR(authority, '@') > 0returns1if the@is present in theauthoritystring, or0if it is not. Therefore the result set is first ordered by this expression, and then by thetimefield, giving rows without the@a priority (since0is sorted before1). We therefore order the 5 rows from the derived table by thetimefield to produce the expected final result.