This query joins the employee, users, and contact tables using the employee ID. It fetches the employee's email, address, name, username, and mobile number in one result.
×
Get Employee Details from Multiple Tables
<?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')
->join('users','employee.emp_id','=','users.emp_id')
->join('contact','employee.emp_id','=','contact.emp_id')
->select('employee.email','employee.address','users.displayName','users.username','contact.mobile')
->get();
echo "<pre>";
print_r($data->toArray());
}
}
Get Employee Details with User and Contact Information
Get Employee Details with User and Contact Information
Get Employee Details with User and Contact Information
This query joins the employee, users, and contact tables using the employee ID. It fetches employee details along with the user's name, username, and mobile number.
×
Get Employee Details with User and Contact Information
<?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')
->join('users','employee.emp_id','=','users.emp_id')
->join('contact','employee.emp_id','=','contact.emp_id')
->select('employee.*','employee.address','users.displayName','users.username','contact.mobile')
->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets the name of one employee whose address is India and gender is O. It returns only the employee's name.
×
Get Employee Name by Address and Gender
<?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'])->value('name');
echo "<pre>";
print_r($data);
}
}
This query gets employee names using their email addresses as keys and displays the result as an array.
×
Get Employee Names by Email
<?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')->pluck('name','email');
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employees whose created_at date is from the year 2024.
×
Get Employees Created in a Specific Year
<?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')->whereYear('created_at','2024')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employees whose created_at month is October.
×
Get Employees Created in October
<?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')->whereMonth('created_at','10')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employees from the employee table whose created_at date is 2024-10-09. It ignores the time and checks only the date.
×
Get Employees Created on a Specific Date
<?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')->whereDate('created_at','2024-10-09')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employees whose created_at date is on the 31st day of any month. It does not check the month or year.
×
Get Employees Created on a Specific Day
<?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')->whereDay('created_at','31')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employees whose ID is not between 10 and 90.
×
Get Employees Outside an ID Range
<?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')->whereNotBetween('id',[10,90])->get();
echo "<pre>";
print_r($data->toArray());
}
}