Fetch Employees with ID Up to 50000
Fetches all employees whose employee ID is less than or equal to 50000 and displays the result.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->where('id','<=',50000)->get(); echo "<pre>"; print_r($data->toArray()); } }
Fetch Employees Within an ID Range
This query fetches all employees whose ID is between 10 and 20.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->whereBetween('id',[10,20])->get(); echo "<pre>"; print_r($data->toArray()); } }
Fetch the First Employee from India with Gender O
This query retrieves the first employee record from the employee table whose address is India and gender is O. It displays the retrieved record using print_r().
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->where(['address'=>'india','gender'=>'O'])->first(); echo "<pre>"; print_r($data); } }
Find a Single Employee by ID
This query finds one employee from the employee table using ID 10 and displays the employee's data.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->find(10); echo "<pre>"; print_r($data); } }
Find Employee by Dynamic ID
This query gets the employee ID from the request and finds that employee from the employee table.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index(Request $request) { $id = $request->id; $data = DB::table('employee')->find($id); echo "<pre>"; print_r($data); } }
Find Employees by Address
This query finds all employees whose address contains the word "india" and displays their records.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->where('address','like','%india%')->get(); echo "<pre>"; print_r($data->toArray()); } }
Find the Minimum Employee ID
This query finds the smallest id value from the employee table.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->min('id'); echo "<pre>"; print_r($data); } }
Get All Employees Except Specific IDs
This query gets all employees from the employee table except the employees whose IDs are 1, 5, and 10.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->whereNotIn('id',[1,5,10])->get(); echo "<pre>"; print_r($data->toArray()); } }
Get All Employees in Descending ID Order
This query gets all employees from the employee table and shows the newest records first based on the ID.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->orderBy('id','desc')->get(); echo "<pre>"; print_r($data->toArray()); } }
Get All Employees in ID Order
This query gets all records from the employee table and sorts them by ID in ascending order.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class Query_Controller extends Controller { public function index() { $data = DB::table('employee')->orderBy('id')->get(); echo "<pre>"; print_r($data->toArray()); } }