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 913711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:36:15+00:00 2026-05-15T17:36:15+00:00

I’m trying to do a query that returns the information of a purchase bill,

  • 0

I’m trying to do a query that returns the information of a purchase bill, but also there’s another table that has detail of the bill, but I need to add that total to the other query, but I can’t add the column, because it says that I need to have in the group by the same objects that in the select, and I tried it this way, but it says that it returns more than one value. Help please! 😀

SELECT fc.fecha_factura_compra AS fecha, fc.id_factura AS no_factura, fc.serie,
       o.abreviatura + CAST(p.corr_id AS VARCHAR(255)) AS codigo_trupp, 
       p.nombre, fc.dias_credito, fc.tipo_cambio, 
       (SELECT SUM(dc.peso_neto * dc.precio_unitario) 
        FROM   detalle_compra AS dc 
        GROUP  BY dc.id_proveedor, 
                  dc.id_factura, 
                  dc.serie) AS total 
FROM   factura_compra AS fc, 
       origen AS o, 
       proveedor AS p, 
       detalle_compra AS dc 
WHERE  fc.id_proveedor = p.id_proveedor 
       AND dc.id_proveedor = p.id_proveedor 
       AND dc.id_factura = fc.id_factura 
       AND p.id_origen = o.id_origen 
       AND dc.serie = fc.serie 
       AND dc.id_factura = fc.id_factura 
       AND dc.id_proveedor = fc.id_proveedor 
       AND fc.activo_inactivo = 'true' 
       AND fc.anulada = 'false'
  • 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-15T17:36:16+00:00Added an answer on May 15, 2026 at 5:36 pm

    Instead of grouping by the columns, you should restrict the sub-select on the join columns and omit detalle_compra from the outer select:

    SELECT fc.fecha_factura_compra as fecha,
           fc.id_factura as no_factura,
           fc.serie,
           o.abreviatura+CAST(p.corr_id as varchar(255)) as Codigo_Trupp,
           p.nombre,
           fc.dias_credito,
           fc.tipo_cambio,
           (select sum(peso_neto*precio_unitario)
              from detalle_compra
             where serie = fc.serie and
                   id_factura = fc.id_factura and
                   id_proveedor = fc.id_proveedor) as Total
      FROM factura_compra as fc,origen as o, proveedor as p
     WHERE fc.id_proveedor = p.id_proveedor and
           p.id_origen = o.id_origen and
           fc.activo_inactivo = 'true' and
           fc.anulada = 'false'
    

    Side note: Use the BIT type to store booleans:

    ...
           fc.activo_inactivo = 1 and
           fc.anulada = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.