Chris Michalczuk
asked on
UNION ALL AND GROUP BY
Is it possible to run in the same sql 2000 query a union all and group by statement
what I am doing is creating a view from 4 different tables which hold a siteid in them.
then i want to get a unique list of them but dont really want to do this in 2 views
create view zAllSiteid
select call_siteid as siteid from tbl_calls
union all
select inventory_siteid as siteid from tbl_inventory
union all
select orders_siteid as siteid from tbl_Orders
then I would do a
select siteid from zAllSite
group by siteid
order by siteid
can i do this in one query?
what I am doing is creating a view from 4 different tables which hold a siteid in them.
then i want to get a unique list of them but dont really want to do this in 2 views
create view zAllSiteid
select call_siteid as siteid from tbl_calls
union all
select inventory_siteid as siteid from tbl_inventory
union all
select orders_siteid as siteid from tbl_Orders
then I would do a
select siteid from zAllSite
group by siteid
order by siteid
can i do this in one query?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks derived table concept is good solution for what i needed to do
Select x.siteid from(
select siteid from zAllSite
group by siteid ) x
order by x.siteid