如何获取 mySql 中用户未申请的所有职位
How to get all jobs that user has not applied to in mySql
我必须 tables、job_postings
和 job_applies
。我怎样才能获得该用户尚未申请的所有工作?
以下是我的 job_postings
table:
的专栏
id, user_id, title, description, duties, salary, child_count, benefits, created_at, updated_at
下面是 job_applies
table
的列
user_id, posting_id, status, created_at, updated_at
我尝试了什么:
$job_postings = DB::table('job_postings')
->select(
'job_postings.title',
'job_postings.description',
'job_postings.duties',
'job_postings.salary',
'job_postings.child_count',
'job_postings.benefits',
'job_postings.created_at',
'job_postings.id AS posting_id',
'job_postings.user_id')
->join('job_applies', 'job_applies.posting_id', '!=', 'job_postings.id')
->where('job_applies.user_id', "=" , user()->id)
->get();
在 Mysql 你应该写(用你的字段列表替换 *)。你可以适应你的语言
SELECT *
FROM JOB_POSTING A
LEFT JOIN JOB_APPLIES B ON B.POSTING_ID = A.ID AND B.USER_ID = A.USER_ID
WHERE B.POSTING_ID IS NULL
或
SELECT *
FROM JOB_POSTING A
WHERE NOT EXISTS (SELECT 1 FROM JOB_APPLIES B WHERE B.POSTING_ID = A.ID AND B.USER_ID = A.USER_ID)
我必须 tables、job_postings
和 job_applies
。我怎样才能获得该用户尚未申请的所有工作?
以下是我的 job_postings
table:
id, user_id, title, description, duties, salary, child_count, benefits, created_at, updated_at
下面是 job_applies
table
user_id, posting_id, status, created_at, updated_at
我尝试了什么:
$job_postings = DB::table('job_postings')
->select(
'job_postings.title',
'job_postings.description',
'job_postings.duties',
'job_postings.salary',
'job_postings.child_count',
'job_postings.benefits',
'job_postings.created_at',
'job_postings.id AS posting_id',
'job_postings.user_id')
->join('job_applies', 'job_applies.posting_id', '!=', 'job_postings.id')
->where('job_applies.user_id', "=" , user()->id)
->get();
在 Mysql 你应该写(用你的字段列表替换 *)。你可以适应你的语言
SELECT *
FROM JOB_POSTING A
LEFT JOIN JOB_APPLIES B ON B.POSTING_ID = A.ID AND B.USER_ID = A.USER_ID
WHERE B.POSTING_ID IS NULL
或
SELECT *
FROM JOB_POSTING A
WHERE NOT EXISTS (SELECT 1 FROM JOB_APPLIES B WHERE B.POSTING_ID = A.ID AND B.USER_ID = A.USER_ID)