2017-04-03 4 views
0

テーブルにはjob_postingsjob_appliesのテーブルが必要です。ユーザーには適用されていないすべてのジョブを取得するにはどうすればよいですか?ユーザーがmySqlに適用していないすべてのジョブを取得する方法

以下

は私job_postingsテーブルの列です:(MySQLで

$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(); 
+0

を適応させることができますか? –

答えて

2

をあなたが書く必要があります。

以下
id, user_id, title, description, duties, salary, child_count, benefits, created_at, updated_at 

job_appliesテーブル

user_id, posting_id, status, created_at, updated_at 

の列は、私が試したどのようなものです*をあなたのフィールドリストに置き換えてください)。あなたはjob_postings内のuser_idは何を意味しているあなたの言語に

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) 
+0

パーフェクト。ありがとう – raqulka

関連する問題