I think it should be not ORDER_BY r.skill_match
, but ORDER BY t.skill_match
instead.
ORDER_BY value within nested query?
-
04-07-2023 - |
Question
I'm currently getting my expected output but I'm looking to now order the query by skill_match
but unsure how to order the current query by skill_match
. skill_match
exists within a nested query.
My question is how would I go about ordering the following query by skill_match
$matches = $this->db->query("
SELECT *
FROM
(SELECT job_string, jobseeker_string, requirement_type,
count(1) / (SELECT count(1) FROM employer_requirements WHERE jobseeker_string = j.jobseeker_string AND requirement_type = 'e' ) AS skill_match
FROM employer_requirements r
INNER JOIN jobseeker_skills j
ON r.skill_string = j.skill_string
GROUP BY job_string, jobseeker_string) t
LEFT JOIN users u
ON t.jobseeker_string = u.string
INNER JOIN applications a
on t.job_string = a.job_string and t.jobseeker_string = a.jobseeker_string
WHERE a.job_string = '".$str."'
ORDER_BY r.skill_match
");
return $matches;
I get the following output when I do a print_r()
and want to ORDER_BY skill_match
value:
Array
(
[0] => Array
(
[job_string] => G2vJhXNUquRELfxQ
[jobseeker_string] => ltyjBhtbHn5knsht
[requirement_type] => e
[skill_match] => 0.2000
[id] => 1
[user_level] => 3
[name] => Steve
[email] => something@hotmail.com
[password] => 3b8751e0f3f81ea085329e44d1d28f2e105f4031efd02ff7430c05d88ce90dcbacaef2f4239882e784b3d133d8aadc88404e670b284b95ab6963b58d00a6b864
[score] => 116
[string] => ltyjBhtbHn5knsht
[date_created] => 2014-04-15 12:16:13
[employer_string] => sm4jBhtbv13knsht
[application_string] => bX0JOwUnhsKEQaAq
)
[1] => Array
(
[job_string] => G2vJhXNUquRELfxQ
[jobseeker_string] => qThkM0OIKVUukp6J
[requirement_type] => e
[skill_match] => 0.4000
[id] => 2
[user_level] => 3
[name] => Bruce
[email] => someone@gmail.com
[password] => 3b8751e0f3f81ea085329e44d1d28f2e105f4031efd02ff7430c05d88ce90dcbacaef2f4239882e784b3d133d8aadc88404e670b284b95ab6963b58d00a6b864
[score] => 116
[string] => qThkM0OIKVUukp6J
[date_created] => 2014-04-15 12:16:13
[employer_string] => sm4jBhtbv13knsht
[application_string] => bX0JOwUnhsKEQaAq
)
)
I appreciate any help.
Solution
OTHER TIPS
The ORDER BY without undercore (_)
$matches = $this->db->query("
SELECT *
FROM
(SELECT job_string, jobseeker_string, requirement_type,
count(1) / (SELECT count(1) FROM employer_requirements WHERE jobseeker_string = j.jobseeker_string AND requirement_type = 'e' ) AS skill_match
FROM employer_requirements r
INNER JOIN jobseeker_skills j
ON r.skill_string = j.skill_string
GROUP BY job_string, jobseeker_string) t
LEFT JOIN users u
ON t.jobseeker_string = u.string
INNER JOIN applications a
on t.job_string = a.job_string and t.jobseeker_string = a.jobseeker_string
WHERE a.job_string = '".$str."'
ORDER BY r.skill_match
");
return $matches;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow