Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Select from another select syntax

Author  Topic 

iancuct
Yak Posting Veteran

73 Posts

Posted - 2005-01-20 : 10:33:32
what is wrong with my syntax? I am trying to do a select from another select

Select * from A
(SELECT Col1, Col2,'DP3' as Location
FROM myTable00
union
SELECT Col1, Col2, 'Sql' as Location
FROM myTable99) as A

after i do the outer select can i group on, or do Max(Col1) for example?

iancuct
Yak Posting Veteran

73 Posts

Posted - 2005-01-20 : 10:41:09
Select A.* from (
SELECT Col1, Col2,'DP3' as Location
FROM myTable00
union
SELECT Col1, Col2, 'Sql' as Location
FROM myTable99) as A
Ok i figured it out myself .. I am bad with parenthasis
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-20 : 11:54:34
Nice naming convention...

I think you might want to Use UNION ALL..UNION Will through out duplicates and incur a sort



SELECT Col1, Col2, Location
FROM (
SELECT Col1, Col2, 'DP3' as Location
FROM myTable00
UNION ALL
SELECT Col1, Col2, 'Sql' as Location
FROM myTable99
) AS XXX





Brett

8-)

EDIT: Oh and use [ code] [ /code ] tags with out the space to keep the code format

Go to Top of Page
   

- Advertisement -