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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query Error

Author  Topic 

SP273
Starting Member

14 Posts

Posted - 2011-02-24 : 14:52:49
hi,

I am trying to write following query & get the error:

SELECT project from
(select distinct Project from dbo.HS_Data_I UNION ALL
select distinct Project from dbo.HS_Data_II)

I get the following error:

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near ')'.

Please let me know where i might be going wrong.

Thanks!


jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-02-24 : 15:03:49
You need to alias your table

SELECT project from
(select distinct Project from dbo.HS_Data_I UNION ALL
select distinct Project from dbo.HS_Data_II) as newTable -- or whatever name you wish to give it


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-02-26 : 09:54:23
if you want distinct values use UNION instead of UNION ALL and remove distincts on selects.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -