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
 Multiple Select Statement

Author  Topic 

NeilG
Aged Yak Warrior

530 Posts

Posted - 2008-08-21 : 05:37:57
Just a quick one I am trying to re-hash some old queries and trying not to use the distinct function but want to return just a distinct value is there a way of grouping but with only one column in the group by clause but having multiple columns in the select statement this is something i have never really had the need to do

I.e

Select col1, col2, col3, col4
from table
group by col1

brings up the usual error

any advice


***************************
Life is for having Fun, and then a little work

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-21 : 05:42:17
Well, if it's not in the group by then you have to use an aggregate function.

Without any sample data it's impossible to say what you are going to need.

(if all the values for one of your non grouped by columns are the same then group by that also).

-------------
Charlie
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-21 : 05:43:30
quote:
Originally posted by NeilG

Just a quick one I am trying to re-hash some old queries and trying not to use the distinct function but want to return just a distinct value is there a way of grouping but with only one column in the group by clause but having multiple columns in the select statement this is something i have never really had the need to do

I.e

Select col1, col2, col3, col4
from table
group by col1

brings up the usual error

any advice


***************************
Life is for having Fun, and then a little work


Can you post some sample data with expected result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-21 : 06:29:46
quote:
Originally posted by NeilG

Just a quick one I am trying to re-hash some old queries and trying not to use the distinct function but want to return just a distinct value is there a way of grouping but with only one column in the group by clause but having multiple columns in the select statement this is something i have never really had the need to do

I.e

Select col1, col2, col3, col4
from table
group by col1

brings up the usual error

any advice


***************************
Life is for having Fun, and then a little work


Apply aggregte functions (MAX,MIN,SUM..)on other columns based on your business rule.
Go to Top of Page
   

- Advertisement -