UNION queries with different number of columns?
You really should not use *.
But if you want to use it anyway, write SELECT invoices.*, 1 to prevent the columns from the customers table from showing up.

Doing an outer join is pointless because any resulting rows that have NULL in customer.id would be filtered out by the WHERE.

And you do not actually need the join, because you have the customer ID value already in the invoices table:

SELECT ... FROM invoices WHERE customer_id IN (64, 66, 63, 62, 65)




Your second approach would work if you removed the second column (1 or 5) from the subqueries.



If you want the  1/5 values to show up in the result, then you must use your first approach (and you can use UNION ALL instead of UNION because there will not be duplicate rows).