Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select 
purchasemaster.date as pdate,
puchasetable.qty as pqty,
puchasetable.wt as pwt 
from purchasemaster 
inner join puchasetable on purchasemaster.PM_id=puchasetable.PM_id 
where puchasetable.G_id=1 
and purchasemaster.date BETWEEN '2014-10-01' and '2014-10-31' 
group by purchasemaster.date 

UNION 
select haladsale.date as sdate,haladsaletable.qty as sqty,
haladsaletable.wt as swt from haladsale 
inner join haladsaletable on haladsale.HS_id=haladsaletable.HS_id 
where haladsale.date BETWEEN '2014-10-01' and '2014-10-31' 
group by haladsale.date

How to get this result?
Please help...
Posted
Updated 10-Nov-14 20:35pm
v2
Comments
sr@22 11-Nov-14 2:44am    
If you are getting any error in this query.
Rajkumar_007 11-Nov-14 2:54am    
No, im not getting any error. but it gives only pdate,pqty and pwt.
i also need sdate,sqty,swt.
is any way?
Ankur\m/ 11-Nov-14 4:15am    
The result is correct. Union will give you that only. If there is no relation between these two resultset you cannot get them in one result.
What are you exactly trying to do.
PS: Use reply link of a comment to reply to it. Clicking 'Have a Question of Comment' won't notify the user.

1 solution

If the query is returning data correctly, then you should be getting
the sdate, sqty and swt records but with the pdate, pqty and pwt column headings.
As the union takes the column names from the first select statement as pdate, pqty and pwt.

What you could do to distinguish the purchasemaster and haladsale records is to add an extra column in you select such as type with a static value, instead of using the column names(pdata and sdate etc)

You could do something like this:
SQL
select 
	'purchasemaster' as type,
	purchasemaster.date as date,
	puchasetable.qty as qty,
	puchasetable.wt as wt 
...

union 

select 
	'haladsale' as type,
	aladsale.date as date,
	haladsaletable.qty as qty,
	haladsaletable.wt as wt
...
 
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