Reputation: 1868
I'm currently joining 2 tables together like this:
$transactions = DB::table('transactions')
->leftjoin('stripe_transactions','transactions.transaction_id','=','stripe_transactions.id')
->orderBy('transactions.id', 'desc')
->get();
My output is not being ordered by the transaction table id though. It's being ordered by the stripe_transactions.id instead.
I've tried reading the docs and creating multiple queries but same results.
Looking for something like this: (This doesn't work due to the where
)
$transactions = DB::table('transactions','transactions.id', 'transactions.transaction_id')
->join('stripe_transactions','stripe_transactions.id')
->where('transactions.transaction_id','=','stripe_transactions.id')
->orderBy('transactions.id', 'desc')
->get();
When I run that query I get the error:
Unknown column '' in 'on clause'
To clear things up I should mention in my table transactions
there is a column called id
and a column called transaction_id
. I want to Order my table by the id
in the transaction table.
Upvotes: 0
Views: 927
Reputation: 3450
I have modified the join
and where
clause in your query. Try the query below:
$transactions = DB::table('transactions')
->join('stripe_transactions','transactions.transaction_id','=','stripe_transactions.id')
->select('transactions.id', 'transactions.transaction_id')
->orderBy('transactions.id', 'desc')
->get();
Upvotes: 1