在laravel 5.6中我想从连接查询中获取数据库在我的情况下我想加入多个表,如员工,指定,预订,车辆,当我使用join时显示以下错误(SQLSTATE [42000]:语法错误或访问冲突:1066不唯一的表/别名:'employees'(SQL:从bookings
选择{来自vehicles
内部加入bookings
。vehicle_id
= vehicles
。vehicle_id
上的employees
内部加入bookings
。driver_id
= employees
。id
内部加入employees
bookings
。conductor_id
= employees
。id
内部加入employees
位于bookings
。helper_id
= employees
。id
内心在designations
上加入employees
。desg_id
= designations
。desc_id
))我谷歌几次,但我找不到任何解决方案如何解决这个问题在这种情况下,您的努力将得到提前感谢。
在我的laravel模型预订
public function get_booking(){
$booking = DB::table('bookings')
->join('vehicles', 'bookings.vehicle_id', '=', 'vehicles.vehicle_id')
->join('employees', 'bookings.driver_id', '=', 'employees.id')
->join('employees', 'bookings.conductor_id', '=', 'employees.id')
->join('employees', 'bookings.helper_id', '=', 'employees.id')
->join('designations', 'employees.desg_id', '=','designations.desc_id')
->get();
return $booking;
答案 0 :(得分:0)
您必须使用表别名并加入<a href="#" onclick="fbShareWindowOpen()">
<span id="fbShareButton">Share this on facebook!</span>
</a>
<script>
function fbShareWindowOpen() {
var myWindow = window.open("https://www.facebook.com/sharer/sharer.php?u=www.url-to-share.com/", "", "top=30px,width=200,height=100");
}
</script>
三次:
designations
您还必须使用列别名(取决于您所需的列):
->join('employees as e1', 'bookings.driver_id', '=', 'e1.id')
->join('employees as e2', 'bookings.conductor_id', '=', 'e2.id')
->join('employees as e3', 'bookings.helper_id', '=', 'e3.id')
->join('designations as d1', 'e1.desg_id', '=','d1.desc_id') -
->join('designations as d2', 'e2.desg_id', '=','d2.desc_id')
->join('designations as d3', 'e3.desg_id', '=','d3.desc_id')