alohaaaron
Programmer
Hi, I have this query. That does a union two combine two tables. But instead of putting the 'closedloans' results next to the 'Total Units Dropped' and 'drop_date' it puts them in the rows below it. How to get them to line up on the same rows? Thanks!
SELECT COUNT(DROP_DATE) AS 'Total Units Dropped',DROP_DATE, NULL AS 'ClosedLoans' FROM inboundtracking d1 RIGHT JOIN marketing_data_nodupe d2 ON d1.DATE BETWEEN d2.DROP_DATE AND (DROP_DATE + INTERVAL 3 MONTH) AND d1.PreApprovalCode = d2.UNIQUE_CUST_ID WHERE DROP_DATE BETWEEN '2010-08-25' AND '2010-09-21' GROUP BY DROP_DATE
UNION
SELECT NULL AS 'Total Units Dropped',NULL AS 'DROP_DATE',COUNT(drop_date) ClosedLoans FROM (
SELECT MAX(drop_date) drop_date FROM marketing_data_nodupe mkt JOIN closedloanlog cll ON mkt.unique_cust_id = cll.unique_cust_id WHERE drop_date BETWEEN '2010-08-25' AND '2010-09-21' AND escrow_funding_date >= drop_date GROUP BY cll.unique_cust_id ORDER BY escrow_funding_date ASC) AS t3 GROUP BY drop_date
SELECT COUNT(DROP_DATE) AS 'Total Units Dropped',DROP_DATE, NULL AS 'ClosedLoans' FROM inboundtracking d1 RIGHT JOIN marketing_data_nodupe d2 ON d1.DATE BETWEEN d2.DROP_DATE AND (DROP_DATE + INTERVAL 3 MONTH) AND d1.PreApprovalCode = d2.UNIQUE_CUST_ID WHERE DROP_DATE BETWEEN '2010-08-25' AND '2010-09-21' GROUP BY DROP_DATE
UNION
SELECT NULL AS 'Total Units Dropped',NULL AS 'DROP_DATE',COUNT(drop_date) ClosedLoans FROM (
SELECT MAX(drop_date) drop_date FROM marketing_data_nodupe mkt JOIN closedloanlog cll ON mkt.unique_cust_id = cll.unique_cust_id WHERE drop_date BETWEEN '2010-08-25' AND '2010-09-21' AND escrow_funding_date >= drop_date GROUP BY cll.unique_cust_id ORDER BY escrow_funding_date ASC) AS t3 GROUP BY drop_date
Code:
"Total Units Dropped" "DROP_DATE" "ClosedLoans"
"15001" "2010-08-25" \N
"13995" "2010-09-20" \N
\N \N "5"
\N \N "16"