我正在嘗試使用查詢生成器進行查詢。我試圖使where
關閉,因此它根據另一個where子句選擇等於存儲在另一個表中的值的值。Laravel查詢其中的值等於另一個表中的值
讓我解釋一下我自己,我有這個表:
select negotiation_id, status_id from negotiations_statuses;
+----------------+-----------+
| negotiation_id | status_id |
+----------------+-----------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
+----------------+-----------+
而這個表:
select * from statuses;
+----+------------+
| id | name |
+----+------------+
| 1 | open |
| 2 | in_process |
| 3 | completed |
| 4 | rejected |
+----+------------+
我想選擇不completed
或rejected
談判。
這是我的嘗試:
$items = DB::table('negotiations')
->join('negotiations_statuses', 'negotiations.id', '=', 'negotiations_statuses.negotiation_id')
->where('user_id', '=', Auth::user()->id)
->where('status_id', '!=', '3')
->where('status_id', '!=', '4')
->get();
它的工作原理,但我明顯是欺騙,因爲我直接使用status_id
。我怎樣才能做這樣的嵌套查詢?
你想使用子查詢或嵌套的查詢嗎? – JMc 2014-11-24 13:35:50
嵌套在哪裏查詢 – dabadaba 2014-11-24 13:37:02