SQLTeam.com | Weblogs | Forums

All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists


#1

select chg_filename as FileCode,file_subject as Subject,max(dt) as SentAt from (select chg_filename,(select department_code from offices where office_code=filetrans.next_office_code)
as dept,file_subject,despatch_date_time as dt from filetrans, FILEMASTER1 where FILEMASTER1.department_code = file_department And FILEMASTER1.section_code = file_section
And file_serial_no = file_serial and FILEMASTER1.file_year=filetrans.file_year and (select department_code from offices where office_code=filetrans.next_office_code)='Su.Pra.'
and (select department_code from offices where office_code=filetrans.office_code)='JAPIT' union Select chg_filename,(select department_code from offices where office_code=
f1.office_code),file_Subject from filetrans f1,FILEMASTER1 f2 where f1.file_department=f2.department_code and f2.section_code=f1.file_section
and f2.file_serial_no = f1.file_serial and (select department_code from offices where office_code=f1.prev_office_code)='JAPIT' and (select department_code from offices where
office_code=f1.office_code)='Su.Pra.') t1 group by chg_filename,dept,file_subject order by max(dt) desc


#2

Here Columlist in first query is chg_filename,dept,file_subject,despatch_date_time but in second select after union there is only 3 columns