Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6666741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:51:37+00:00 2026-05-26T02:51:37+00:00

I have this queries, but I need to make a Union for all. But

  • 0

I have this queries, but I need to make a Union for all. But each query has a different quantity of columns in the select-list, which gives me the error:

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

How can I fix this to avoid the error?

     Select 'Pregunta:(8-9-10)Totales No Coinciden' as Descripcion_Error, c_Fk_IdBoleta as Boleta,
       f_TotalAreaExtensionFinca as Extension_Total, f_TotalAreaDedicadaFinca 
       as Area_Dedicada_Finca, f_TotalAreaTenenciaFinca as Tenencia_Finca
      from Fnc_TenenciaUsoTierra
      where (f_TotalAreaExtensionFinca <> f_TotalAreaDedicadaFinca OR f_TotalAreaExtensionFinca <> f_TotalAreaTenenciaFinca) 
      AND  Fnc_TenenciaUsoTierra.c_Fk_IdBoleta = @id_Boleta


UNION 

SELECT 'Pregunta (12) El área sembrada es mayor al área dedicada a cultivos' as Descripcion_Error,
   c_Fk_IdBoleta as Boleta,
   (SELECT SUM(f_AreaDedicadaCultivos)
      FROM Fnc_TenenciaUsoTierra
      WHERE c_Fk_IdBoleta = sembrado.c_Fk_IdBoleta)
   AS AreaDedicadaCultivos,
   SUM(sembrado.f_AreaSiembra) as AreaSembrada
FROM
   Clt_Sembrado as sembrado
WHERE
   sembrado.c_Fk_IdBoleta = 45550711
GROUP BY sembrado.c_Fk_IdBoleta
HAVING SUM(sembrado.f_AreaSiembra) > (SELECT SUM(f_AreaDedicadaCultivos)
      FROM Fnc_TenenciaUsoTierra
      WHERE c_Fk_IdBoleta = sembrado.c_Fk_IdBoleta)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:51:37+00:00Added an answer on May 26, 2026 at 2:51 am

    You have to have the same number of columns on each side of the UNION. You can always add dummy columns to get there – and fill them with NULLs or the “not applicable” value of your choice.

    SELECT 'Pregunta (12) El área sembrada es mayor al área dedicada a cultivos' as Descripcion_Error,
       c_Fk_IdBoleta as Boleta,
       (SELECT SUM(f_AreaDedicadaCultivos)
          FROM Fnc_TenenciaUsoTierra
          WHERE c_Fk_IdBoleta = sembrado.c_Fk_IdBoleta)
       AS AreaDedicadaCultivos,
       SUM(sembrado.f_AreaSiembra) as AreaSembrada, 
       NULL as Tenencia_Finca
    FROM Clt_Sembrado as sembrado
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might sound rudimentary but, I have created tables by running queries in Workbench
I have a lot of SQL queries like this: SELECT o.Id, o.attrib1, o.attrib2 FROM
I have ran across a few queries that use this where condition: select ...
I have two queries use [DatabaseAA] select * ,DATEDIFF(MINUTE,SomeDate,'3/28/2012 12:52:25 PM +00:00') This passes,
I always have trouble with complicated SQL queries. This is what I have $query
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have a large xml file (1Gb). I need to make many queries on
I'm trying to make this query work, in my model Workshop I have a
I have this table in my database, and i need to add 1 each
I have this in Model: public function index_loop() { $post_user = $this->db->query(SELECT posts.post_title, posts.post_content,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.