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
 Need to select distinct field

Author  Topic 

ldcaudle
Starting Member

1 Post

Posted - 2009-03-18 : 11:15:57
From the following query I want to select the distinct pe.code24. I'm new to SQL 2005 and when I do this on my own, I get message "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. So I have left my upper nest statement out and only include the main query.

SELECT st_Project.description AS [Project Name], st_Work.description AS [Work Name], pe.planning_code, pe.ppl_code, pe.code24,
st_Code24.description AS Cust_Exec_Sponsor_24, st_Code24.depth
FROM ip.planning_entity AS pe INNER JOIN
ip.structure AS st_Code24 ON pe.code24 = st_Code24.structure_code INNER JOIN
ip.structure AS st_Work ON pe.planning_code = st_Work.structure_code INNER JOIN
ip.structure AS st_Project ON pe.ppl_code = st_Project.structure_code
WHERE (pe.code24 IS NOT NULL) )

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-03-18 : 23:08:10
why r u joining the same table multiple times

try this once
select col..........
FROM (SELECT DISTINCT code24,planning_code,ppl_code FROM ip.planning_entity ) AS pe
INNER JOIN
ip.structure AS st_Code24 ON pe.code24 = st_Code24.structure_code
AND pe.planning_code = st_Code24.structure_code
AND pe.ppl_code = st_Code24.structure_code
where cond................
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 14:09:54
so what should be your output format?also are you using sql 2005?
Go to Top of Page
   

- Advertisement -