@jgravois I don’t really understand. List of distinct what? They’re rows from three separate tables.
May 18, 2021
4
Level 33
Merge three collections and remove duplicates
I have three tables (customer_quotes, sales, posted_invoices) that each contain a company_code field.
I need an iterable of the distinct values to run through an update script.
How would I combine these three to only have a list of distincts?
$cqs = DB::table('customer_quotes')->select('company_code')->distinct()->get();
$sqs = DB::table('sales')->select('company_code')->distinct()->get();
$pqs = DB::table('posted_invoices')->select('company_code')->distinct()->get();
Level 2
please try
$cqs = DB::table('customer_quotes')->select('company_code');
$sqs = DB::table('sales')->select('company_code');
$pqs = DB::table('posted_invoices')->select('company_code');
$unique = $cqs->union($sqs)->union($pqs)->distinct()->get();
Please or to participate in this conversation.