Select 除某些行外的所有行 laravel
Select all except some rows laravel
假设我有车 table 并且我有 2 列:型号、颜色。
id model color
------ -------- ----------
1 Ford yellow
2 Ford green
3 Ford red
4 Ford yellow
5 Subaru yellow
6 Subaru red
我不想带福特车型和黄色。我怎样才能用 eloquent 做到这一点。我需要这个条件。
WHERE NOT (model = 'Ford' AND color = 'yellow')
感谢帮助
只需使用 !=
运算符。
WHERE (model != 'Ford' AND color != 'yellow')
这样试试...
Select * from car where NOT model = 'ford' AND NOT color = 'yellow'
这对你有用...
试试这个...
$products = Modelname::where('model','!=','Ford')->orwhere('color','!=','yellow')->get();
Its same as
SELECT * FROM tablename WHERE model != 'Ford' OR color != 'yellow';
输出:
Array ( [0] => Array ( [id] => 0 [model] => Ford [color] => green )
[1] => Array ( [id] => 0 [model] => Ford [color] => red )
[2] => Array ( [id] => 0 [model] => Subaru [color] => yellow )
[3] => Array ( [id] => 0 [model] => Subaru [color] => red ) )
where('model', '!=', 'ford', 'AND', 'color', '!=', 'yellow')
假设我有车 table 并且我有 2 列:型号、颜色。
id model color
------ -------- ----------
1 Ford yellow
2 Ford green
3 Ford red
4 Ford yellow
5 Subaru yellow
6 Subaru red
我不想带福特车型和黄色。我怎样才能用 eloquent 做到这一点。我需要这个条件。
WHERE NOT (model = 'Ford' AND color = 'yellow')
感谢帮助
只需使用 !=
运算符。
WHERE (model != 'Ford' AND color != 'yellow')
这样试试...
Select * from car where NOT model = 'ford' AND NOT color = 'yellow'
这对你有用...
试试这个...
$products = Modelname::where('model','!=','Ford')->orwhere('color','!=','yellow')->get();
Its same as
SELECT * FROM tablename WHERE model != 'Ford' OR color != 'yellow';
输出:
Array ( [0] => Array ( [id] => 0 [model] => Ford [color] => green )
[1] => Array ( [id] => 0 [model] => Ford [color] => red )
[2] => Array ( [id] => 0 [model] => Subaru [color] => yellow )
[3] => Array ( [id] => 0 [model] => Subaru [color] => red ) )
where('model', '!=', 'ford', 'AND', 'color', '!=', 'yellow')