sql - If an UNION doesn't contain the same column I can't use it? -
i read online:
each query in union
must contain same columns, expressions, or aggregate functions, , must listed in same order.
if saying if have query example
select top (1) ties employee_id, sum(stars) 'total' table_a group employee_id order 'total' desc
i can't use union
different table_b
name of employee table_a
doesn't have. table_b
share employee_id
call differently emp_id
, output name of employee table_b
has emp_namefirst
, emp_namelast
.
what saying queries in union must produce result sets same schema. says absolutely nothing original source tables. long subqueries produce same number of columns same data types , in same order you're fine. point of union single result set there can 1 set of columns each subquery's result set must match that.
from you've described, union irrelevant you. union adds rows. want add columns. want join, not union.
Comments
Post a Comment