Error in sql Query using distinct

Posted by Klbaiju under Sql Server on 8/5/2010 | Views : 3047 | Status : [Member] | Replies : 2
Hi,
following is my sql query


select acode.vcassociatename,pd.vcplacenames,pd.inday,pd.vcpackagecode,pe.vcpackagename,pe.vcallplacenames from packagedetails pd,packageextras pe,associates acode where pe.vcpackagecode=pd.vcpackagecode and pe.vcassociatecode=acode.vcassociatecode and pe.vclanguage='english' order by pd.inday

this is working fine.
but i need the distinct values.

i try this example

select distinct(acode.vcassociatename),distinct(pe.vcallplacenames),distinct(pd.vcpackagecode),distinct(pe.vcpackagename)from packagedetails pd,packageextras pe,associates acode where pe.vcpackagecode=pd.vcpackagecode and pe.vcassociatecode=acode.vcassociatecode and pe.vclanguage='english'

error is showing
this is the error
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'distinct'.

what is the correct query

Regards
K L BAIJU




Responses

Posted by: Poster on: 8/5/2010 [Member] Starter

Up
0
Down
Your query will not work in this way, you can't have multiple distinct in the same query.

You can get your desired results in following ways

Select vcassociationName = (Select distinct associationName from yourTable), vcpackageCode = (Select distinct packageCode from yourTable)


This means that you will have to use sub query.

Hope this helps



Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 8/9/2010 [Member] Bronze

Up
0
Down
Multiple distinct coloums can be applied on a single query.
use sub query or use group by

Thanks
Pavan Kumar
Mark Answer if this fits the need

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response