Basically, I want have two separate SQL queries, but I want them to be displayed in the same result set. However, the first query returns several columns and the second query only returns one column.
If I want the results from the second query to simply be added on as an additional column to the results from the first query, how do I do this?
Query 1:
SELECT cr.COMMUNICATION_ID, cr.CONSUMER_ID, cr.ACTION_LOG_ID, cal.CONSUMER_ID, cal.TIPS_AMOUNT, cal.LAST_MOD_TIME
FROM COMMUNICATION_RELEVANCE AS cr
JOIN consumer_action_log AS cal
ON cr.ACTION_LOG_ID=cal.ACTION_LOG_ID;
QUERY 2:
SELECT AVG(TIPS_AMOUNT) AS AVG_TIPS
FROM CONSUMER_ACTION_LOG
JOIN COMMUNICATION_RELEVANCE
ON CONSUMER_ACTION_LOG.SENDER_CONSUMER_ID=COMMUNICATION_RElEVANCE.consumer_id;
Basically, I want a UNION, but for queries with different number of columns.
I think you actually want to add one column, not one row as the other answers suggest
The trick is that you join to the query that produces the single row, single column AVG value.