{"id":181,"date":"2012-04-27T09:45:17","date_gmt":"2012-04-27T09:45:17","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/04\/27\/all-queries-combined-using-a-union-intersect-or-except-operator-must-have-an-equal-number-of-expressions-in-their-target-lists\/"},"modified":"2012-04-27T09:45:17","modified_gmt":"2012-04-27T09:45:17","slug":"all-queries-combined-using-a-union-intersect-or-except-operator-must-have-an-equal-number-of-expressions-in-their-target-lists","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/04\/27\/all-queries-combined-using-a-union-intersect-or-except-operator-must-have-an-equal-number-of-expressions-in-their-target-lists\/","title":{"rendered":"All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."},"content":{"rendered":"
Error: Reason: Fix: Sample example code <\/p>\n Before: After: Error: Msg 205, Level 16, State 1, Line 1 All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists. Reason: The select statements in the clause do not have the same number of columns. Fix: Make sure that all the starements using UNION, INTERSECT…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[1835,1836,1837],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-sql-errors","tag-all-queries-combined-using-a-union-intersect-or-except","tag-msg-205","tag-msg-205-level-16-state-1-line-1"],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n
\nMsg 205, Level 16, State 1, Line 1
\nAll queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
\n<\/font><\/p>\n
\nThe select statements in the clause do not have the same number of columns.<\/p>\n
\nMake sure that all the starements using UNION, INTERSECT or EXCEPT operator have same number of expressions(columns).
\nUse column names instead of using * in the select list.<\/p>\n
\n[sql]
\nSELECT 1
\nUNION
\nSELECT 2,3
\n[\/sql]<\/p>\n
\n[sql]
\nSELECT 1,NULL
\nUNION
\nSELECT 2,3
\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"