Using WHERE statement after UNION in SQL Server

SajidHussa
 
on Aug 24, 2021 01:53 AM
376 Views

i want implement where clause in this query 

my query is 

select itemgroupname,itemgroupid ,'','' from tbl_itemgroup 
union 
select itemsubgroupname,itemgroupid,itemsubgroupid,'' from tbl_itemsubgruop 
union 
select proname,itemgroupid,itemsubgroupid,pid from tbl_productentry

where itemgroupname = na

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 24, 2021 01:53 AM

Hi SajidHussa,

Refer below query.

SQL

SELECT * FROM (
	select itemgroupname,itemgroupid ,'','' 
	from tbl_itemgroup 
	union 
	select itemsubgroupname,itemgroupid,itemsubgroupid,'' 
	from tbl_itemsubgruop 
	union 
	select proname,itemgroupid,itemsubgroupid,pid 
	from tbl_productentry
) t
where t.itemgroupname = 'na'