bobin56 bobin56 - 8 months ago 68
MySQL Question

Ambiguous column name laravel 5.3

I know this question has been asked plenty of times but all answers somehow they don't seem to work somehow . i have to work on a poorly designed SQL database that has no documentation whatsoever and i am trying to join results from the two tables but nothing seems to work and keep getting the ambiguous column error all the time . Here is my code :

$payments = DB::table('dbo.T_PAY_SEND')->where('SEND_SUCC',0)->orderBy('SEND_DATE', 'desc')->get();

foreach ($payments as $pay) {

$orders[]= T_Order::select(DB::raw('dbo.T_PAY_SEND.METERID as PAY_METER_ID, dbo.T_Order.METERID as ORDER_METER_ID'))->Join('dbo.T_PAY_SEND','dbo.T_PAY_SEND.METERID','=','dbo.T_Order.METERID')->where('METERID', '=',$meterID)->where('Order_Value', '!=', '')->get('PAY_METER_ID','ORDER_METER_ID');


If anyone could help i will truly appreciate :-)

Answer Source

You have the same column name in 2 tables,so here

where('METERID', '=',$meterID)

You have to specify the table,either


where('dbo.T_Order.METERID', '=',$meterID)