我们如何在laravel中使用self join

时间:2018-05-30 09:40:02

标签: laravel-4

SELECT name, email, users.password
FROM users
INNER JOIN(
SELECT password
FROM users
GROUP BY password
HAVING COUNT(password) >1
)temp ON users.password= temp.password
where email = 'Excep@yesbus.com';

转换此laravel查询构建,我尝试了方法,但看到找不到错误基本视图

User::select('user_id, name, type, email, username, password')
                        ->join('temp', 'users.password', '=', 'temp.password')
                        ->groupBy('password')   
                        ->having('password', '>',1)
                        ->where('email', Input::get('username'))
                        ->get();
                    tried this does not work can anyone please suggest how we can do this thanks in advance

1 个答案:

答案 0 :(得分:0)

尝试这种方式可以帮助你

$email = Input::get('username');

$users = DB::select( DB::raw("SELECT name, email, username, users.password FROM users INNER JOIN( SELECT password FROM users GROUP BY password HAVING COUNT(password) >1 )temp ON users.password= temp.password where email = '$email'") );