如何在 laravel 查询(eleqouent 和原始查询)中使用 IN 运算符?
how to use IN operator in laravel query (eleqouent and raw query)?
我需要使用 IN
运算符从数据库中获取数据。我尝试如下使用它并出现错误:
$pr =DB::('select * from prstuff p where p.pid in (select pid from prdrop)');
我是 Laravel 的新手,不知道如何使用像 IN
这样的运算符,所以请向我解释如何使用它。
您没有在数据库上调用任何函数 class。您可以像这样调用 select 函数 DB::select ()
$pr =DB::select('select * from prstuff p where p.pid in (select pid from prdrop)');
您可以像这样在 DB::raw()
中设置自定义 select :
DB::select(DB::raw('select * from prstuff p where p.pid in (select pid from prdrop)'));
或者您可以像这样使用 whereIn()
:
DB::table('prstuff')
->select('*')
->whereIn('pid', function($query)
{
$query->select('pid')
->from('prdrop');
})
->get();
我需要使用 IN
运算符从数据库中获取数据。我尝试如下使用它并出现错误:
$pr =DB::('select * from prstuff p where p.pid in (select pid from prdrop)');
我是 Laravel 的新手,不知道如何使用像 IN
这样的运算符,所以请向我解释如何使用它。
您没有在数据库上调用任何函数 class。您可以像这样调用 select 函数 DB::select ()
$pr =DB::select('select * from prstuff p where p.pid in (select pid from prdrop)');
您可以像这样在 DB::raw()
中设置自定义 select :
DB::select(DB::raw('select * from prstuff p where p.pid in (select pid from prdrop)'));
或者您可以像这样使用 whereIn()
:
DB::table('prstuff')
->select('*')
->whereIn('pid', function($query)
{
$query->select('pid')
->from('prdrop');
})
->get();