shammon shammon - 7 months ago 24
SQL Question

Laravel query builder: error in mysql where clause

Here is my join query

$data['userslist'] = DB::table('users')

But i will get the following error in where clause

check the manual that corresponds to your MariaDB server version for
the right syntax to use near '
where `users`.`user_type` != ?' at
line 1 (SQL: select `users`.*, `user_roles`.`role_name` from `users`
inner join `user_roles` on `users`.`user_type=user_roles`.`role_id`

!= 1)


You try to fetch users.user_type where value in not equal to 1. For this, you need to use '<>' in where clause

Now your query is as follow :

$data['userslist'] = DB::table('users')
        ->join('user_roles', 'users.user_type', '=', 'user_roles.role_id')

I hope you will get your solution.