Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

david001's avatar

join not working as expected

I have a table name payments,sold_pin and claim_users. I need to fetch data form payments ,sold_pin and claim_users if only status(column_name) of sold_pin is 1

 $payments =  DB::table('payments')
        ->join('claim_users','payments.product_id','=','claim_users.product_id')
        ->join('sold_pin','payments.product_id','=','sold_pin.product_id')
        ->where('sold_pin.status','=',1)
        ->get();

But i got all results as i should get results only if status of sold_pin is 1

Three are 3 records in my payments,sold_pin and claim_users table and all have table same product_id.

I should get 3 records but i got 8 records

0 likes
3 replies
rsands's avatar

@david001 This is going to be hard to diagnose without seeing a sample of the data, sometimes you need to alter the query orders

david001's avatar

Three are 3 records in my payments,sold_pin and claim_users table and all have table same product_id.

I should get 3 records but i got 8 records

Please or to participate in this conversation.