#Join with OR on some conditions - how to group

3 messages · Page 1 of 1 (latest)

unreal mist
#

Looking at the raw output using ->OrOn, it does produce the wrong query. I need some way to group and can't find it in the docs.

SELECT *
FROM   `statement_transactions` AS `st`
       INNER JOIN `quickbooks_transactions` AS `qb`
               ON `st`.`statement_id` = `qb`.`statement_id`
                  AND `st`.`invoice_nbr_clean` = `qb`.`invoice_nbr_clean`
                  AND `st`.`transaction_date` = `qb`.`transaction_date`
                  AND `st`.`transaction_type_id` = `qb`.`transaction_type_id`
                  AND `st`.`original_amount` = `qb`.`original_amount`
                   OR `st`.`balance` = `qb`.`balance`
WHERE  `st`.`statement_id` = ?
       AND `qb`.`found_in_quickbooks` = ?
       AND `qb`.`quickbooks_ref_id` IS NOT NULL 
unreal mist
#

I've tried doing various things like this:

$join->on(DB::raw('(st.original_amount=qb.original_amountORst.balance=qb.balance)'));

both backticks and single quotes, and the error message output is trying to do this:

UPDATE statement_transactions AS st
INNER JOIN quickbooks_transactions AS qb
ON st.statement_id = qb.statement_id
AND st.invoice_nbr_clean = qb.invoice_nbr_clean
AND st.transaction_date = qb.transaction_date
AND st.transaction_type_id = qb.transaction_type_id
AND ( st.original_amount = qb.original_amount
OR st.balance = qb.balance ) = ``

tough prism
#

Did you tried using Eloquent and the Query Builder to do what you want?