0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LaravelのwhereとwhereColumnの違い

0
Posted at

Laravelのサブクエリの結合条件を複数使うときに、whereとwhereColumnの違いを理解していなかったので、この機会に軽い忘備録としてまとめました。

whereの役割

・カラムと値を比較する
・値はリテラル値および変数が使われる

index.php
->where('id', 1);
->where('id', $userId);

whereColumnの役割

・カラムとカラムを比較する
・SQLでいうcolumnA = columnB
・join句のonと同じ用途で使われる

index.php
->whereColumn('users.id', '=' ,'books.user_id');

以上、whereとwhereColumnの違いについて簡単にまとめました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?