Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How do I get the result below,

combining two queries?

I want. Together with the results below.

code 1:salestaxinvoice

SELECT
entity.entityid as entity_entityid,
entity.entityuserid as entity_entityuserid,
entity.entity_firstname as entity_entity_firstname,
personnel.personneluserid as personnel_personneluserid,
personnel.personnelfirstname as personnel_personnelfirstname,
sum(salestaxinvoiceitem.netamount) as sumnetamount
FROM
salestaxinvoice
LEFT JOIN salestaxinvoiceitem ON salestaxinvoice.salestaxinvoiceid = salestaxinvoiceitem.salestaxinvoiceid
LEFT JOIN personnel ON arsalestaxinvoice.personnelid_sales = personnel_tbl.personnelid
LEFT JOIN matunit on salestaxinvoiceitem.sourceid_matunitid = matunit.matunitid
LEFT JOIN mat on matunit.matunituserid = mat_tbl.matuserid
LEFT JOIN entity on salestaxinvoice.customerid = entity_tbl.entityid
LEFT JOIN matcategory ON mmmatunit.matcategoryid = matcategory.matcategoryid
WHERE
to_date(to_char(salestaxinvoice.processed ,'yyyy-mm-dd'),'yyyy-mm-dd') between '2013-01-01' and '2013-01-31'

AND personneluserid = 'P10'
AND(matcategory.matcategoryid <> '010000')
AND (maentity_tbl."entityuserid" = 'A001'
OR maentity_tbl."entityuserid" = 'A002')
GROUP BY
entity.entityid,
entity.entityuserid ,
entity.entity_firstname ,
personnel.personneluserid ,
personnel.personnelfirstname ,
salestaxinvoiceitem.netamount


code 2:creditnote

SELECT distinct
entity.entityid as entityid,
entity.entityuserid as entityentityuserid,
entity.entity_firstname as entityentityfirstname,
sum(creditnoteitem.amount) as sumcreditnoteitem_amount
FROM
creditnote
LEFT JOIN creditnoteitem ON creditnote.creditnoteid = creditnoteitem.creditnoteid
LEFT JOIN entity ON creditnote.customerid = entity.entityid
LEFT JOIN salespersonnel_tbl ON entity_tbl.entityid = entitysalespersonnel.entityid
LEFT JOIN personnel ON entitysalespersonnel.personnelid = personnel.personnelid
WHERE
to_date(to_char(salestaxinvoice.processed ,'yyyy-mm-dd'),'yyyy-mm-dd') between '2013-01-01' and '2013-01-31'
personneluserid = 'P10'
AND (maentity_tbl."entityuserid" = 'A001'
OR maentity_tbl."entityuserid" = 'A002')
GROUP BY
entity.entityid,
entity.entityuserid,
entity.entity_firstname,
creditnoteitem_tbl.amount
ORDER BY
entity.entityuserid ASC



RESULT:
entityuserid , entityfirstname , salestaxinvoiceitem_netamount , sumcreditnote_amount , result

A001 , Kesha , 12,000 , 1,200 , 10,800

A002 , Frank , 9,000 , 4,000 , 5,000

A003 , Paula , 5,000 , 2,500 , 2,500
Posted

1 solution

UNION or
string query ="bla bla bla";
string query2 ="bla bla bla bla";

query = query2 + " UNION " +"bla bla bla";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900