I have tried all the existing attempts with a standard select query by nesting in another SELECT, then resorting with ASC, but it fails to load for some reason in my JSCharts. My code is working properly, minus the order:
SELECT `$tableName`.`$patient_idField` , `$tableDataName`.`$patient_idField` , `$tableDataName`.`$resultField` , `$tableName`.`$login_idField`
FROM `$tableName`
JOIN `$tableDataName` ON `$tableName`.`$patient_idField` = `$tableDataName`.`$patient_idField`
COLLATE utf8_general_ci
WHERE `$tableName`.`$login_idField` = $usssName
ORDER BY `$tableDataName`.id DESC LIMIT 10
Here is the attempt to re-order, that failed to load:
SELECT * FROM (
SELECT `$tableName`.`$patient_idField` , `$tableDataName`.`$patient_idField` , `$tableDataName`.`$resultField` , `$tableName`.`$login_idField`
FROM `$tableName`
JOIN `$tableDataName` ON `$tableName`.`$patient_idField` = `$tableDataName`.`$patient_idField`
COLLATE utf8_general_ci
WHERE `$tableName`.`$login_idField` = $usssName
ORDER BY `$tableDataName`.id DESC LIMIT 10 ) AS `$tableName` JOIN `$tableDataName` ORDER by `$tableDataName`.id ASC
UPDATED WITHOUT PHP...
SELECT userlist.patient_id, results.patient_id, results.result, userlist.login_id
FROM userlist
JOIN results ON userlist.patient_id = results.patient_id
COLLATE utf8_general_ci
WHERE userlist.login_id = ####
ORDER BY results.id DESC
LIMIT 10
Now if I perform anything outside of this to ASC it returns an error on duplicate of patient_id
.
The code that worked, for future reference
SELECT *
FROM (
SELECT userlist.patient_id, results.result, userlist.login_id, results.id
FROM userlist
JOIN results ON userlist.patient_id = results.patient_id
COLLATE utf8_general_ci
WHERE userlist.login_id = ####
ORDER BY results.id DESC
LIMIT 10 ) temp
ORDER BY id
It involved removing one of the .patient_id
on SELECT.