I have table, 'jobs', indexed by job_id, and and table discussions with foreign key 'job_id'.
In jobs I have a column called 'summary', and in discussions a column called 'body'. I want to search for the same text string in both of these columns across both these tables and return the applicable jobs.
Eg, if a jobs record with job_id=7 has the string 'somestring' in it's 'summary' column, and a discussions record has foreign key job_id=20 and has string 'somestring', I want the job records for job_id=7 and job_id=20 returned.
I am using laravel. I'm having trouble finding a solution, this is the closest I have got:
$query->join('discussions', function( $join ) use ( $search_term ){
$join->on('jobs.job_id', '=', 'discussions.job_id');
$join->where('discussions.body', 'LIKE', $search_term );
$join->orWhere('jobs.summary', 'LIKE', $search_term );
})
But this just returns everything from my discussions table. Does anyone have any suggestions?
Thanks :)