-2

I have two queries. One is gross sale and other is net sale. I want to report in a single query. How can I do that?

Gross Sale

Location Name                                     Gsale 
(sub-dealer-temp)                                   2   
2049 (Sub-Dealer) Always Protected, LLC             3   
2052 (Sub-Dealer) Alert Security, Inc               4   
2055 (Sub-Dealer) Alarm Connection, LLC             5   
2067 (Sub-Dealer-t) Activation Dept, LLC            67  
2068 (Sub-Dealer-t) Premier Security USA, LLC       8   

Net Sale

location Name                                     Nsale 
2055 (Sub-Dealer) Alarm Connection, LLC             5   
2067 (Sub-Dealer-t) Activation Dept, LLC           67   
2068 (Sub-Dealer-t) Premier Security USA, LLC       8   
2783 ((Sub-Dealer-t) Premier abc                    45  
2783 ((Sub-Dealer-t) Premier xyz                    32  

Result

Lc.Name                                Gsale             Nsale
(sub-dealer-temp)                        2               null
2049 (Sub-Dealer) Always Protected, LLC  3               null
2052 (Sub-Dealer) Alert Security, Inc    4               null
2055 (Sub-Dealer) Alarm Connection, LLC  5                5
2067 (Sub-Dealer-t) Activation Dept, LLC 67               67
2068 (Sub-Dealer-t) Premier Security US  8                8
2783 ((Sub-Dealer-t) Premier abc        null              45
2783 ((Sub-Dealer-t) Premier xyz        null              32
1
  • 6
    Hint: UNION Commented Oct 4, 2016 at 7:48

2 Answers 2

0

you can use a join or union below is the join query

     select g.location,g.name,g.Gsale,n.Nsale from gross sale g 
     join net sale n on g.location=n.location
Sign up to request clarification or add additional context in comments.

1 Comment

please learn to format a vertical block. Thx
0

You can use bellow sql code:

Table name 1 : Gross Sale is now gross_sale and column name lcName, Gsale

Table name 2 : Net Sale is now net_sale and column name lcName, Nsale

SELECT a.lcName, a.Gsale, b.Nsale FROM gross_sale a 
FULL OUTER JOIN net_sale b ON a.lcName=b.lcName ORDER BY a.lcName;

4 Comments

you want a full outer join not a left join right? See the column Gsale?
@Drew can you explain clearly?
What does a left join do?
@Drew Sorry for that, yes it will FULL OUTER JOIN.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.