我有两张桌子&travel ;request'表和' travel_details'表
travel_request table
id name
1 aa
2 bb
traveling_details table
id travel_request_id(FK from travel_request) country
1 1 UK
2 1 CL
3 2 Australia
4 2 India
我想列出travel_request_id = 1和travel_request_id = 2的travel_request_id 1记录的一条记录以及travel_request表格详细信息和其他
$request = DB::table('travel_request')
->join('department', 'travel_request.department_id', '=', 'department.id')
->join('users', 'travel_request.approver_id', '=', 'users.id')
->join('travel_purpose', 'travel_request.travel_purpose_id', '=', 'travel_purpose.id')
->join('traveling_details', 'travel_request.id','=','traveling_details.travel_request_id' )
->join('country','country.id', '=', 'traveling_details.country_id')
->join('travel_request_status','travel_request.status_id', '=', 'travel_request_status.id')
->select('travel_request.*', 'travel_request.id as travel_id','department.name as dept_name','users.firstname as approver_name','travel_purpose.purpose','country.name as country_name','traveling_details.from_date','traveling_details.to_date','travel_request_status.status')->where('travel_request.requestor_id',$user_id)->paginate(2);
此查询显示traveling_details表中的所有记录
答案 0 :(得分:0)
您可能已经使用任何类型的ORM进行数据库事务处理。尝试在该查询中使用LIMIT 1
。
答案 1 :(得分:0)