I have this EMPLOYEE table of employees list
+-----+---------------+-------------+
| ID |EMPLOYEE_ID | SKILLS |
+-----+---------------+-------------+
| 1 | 1 | 3,4 |
+-----+---------------+-------------+
| 2 | 2 | 3,5,2 |
+-----+---------------+-------------+
| 3 | 3 | 1,5 |
+-----+---------------+-------------+
and table POSTED_JOB listing jobs
+-----+---------------+-------------+
| ID |POSTED_JOB_ID | JOB_SKILLS |
+-----+---------------+-------------+
| 1 | 1 | 1,2,3 |
+-----+---------------+-------------+
| 2 | 2 | 3,4 |
+-----+---------------+-------------+
| 3 | 3 | 5,4 |
+-----+---------------+-------------+
| 4 | 4 | 5,6 |
+-----+---------------+-------------+
How can I get all jobs posted with skills corresponding to the skills of employees with laravel query.
For example for employee with employee_id 1, the jobs would be 1,2, and 3.
I tried with find_in_set but here both are lists. DB::raw("find_in_set(EMPLOYEE.SKILLS , POSTED_JOB.JOB_SKILLS)"), DB::raw(''), DB::raw(''))
$skills = 'select the employee skills';
$skl_arr = explode(',',$skills);
$skl_length = count($skl_arr);
/*query */
$rows->orwhere(DB::raw("find_in_set('$skl_arr[0]','post_job.skills')"));
for ($i=1; $i < $skl_length ; $i++) {
$rows->$join->on(DB::raw("find_in_set('$skl_arr[$i]','post_job.skills')",DB::raw(''),DB::raw('')));
}
You can try this over join
DB::table('POSTED_JOB')->leftJoin('EMPLOYEE', function($join){
$join->on(DB::raw("find_in_set(POSTED_JOB.JOB_SKILLSmEMPLOYEE.SKILLS)"));
});
您可以尝试在两列中进行搜索。
SELECT * FROM order1 WHERE FIND_IN_SET(order_no,'$foo') OR awb_no IN ('$foo')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.