Quantcast
Channel: Questions in topic: "union-all"
Viewing all articles
Browse latest Browse all 18

Select by union with different number of columns

$
0
0
I have two tables as given CashRegister SalesOrder Date PaymentId CustId VenId Debit Credit Date SaleOrderId CustId Debit Credit 2/2/12 Pay_1 Cus_1 444 3/2/2012 So_1 Cus_1 666 4/2/12 Pay_2 Ven_1 555 From These two tables, I have to generate a report like: Joural Report Date TrId AccountId Debit Credit 2/2/12 Pay_1 Cus_1 444 3/3/12 So_1 Cus_1 666 4/2/12 Pay_1 Ven_1 555 Here, I have tried this query select * from( select Date,PaymentId TrId,CustId AccountId,VenId, AccountId,Debit,Credit from CashRegister union select Date,SaleOrderId TrId,CustId AccountId,Debit,Credit) t order by Date But it gives an error that " In Union number of expressions should be equal for target list. How to solve this, please help me i need it badly

Viewing all articles
Browse latest Browse all 18

Trending Articles