ICSAutomation
asked on
SQL select without identical values
Hello
I have a table "MyTable" with the fields: MyTable.Id, MyTable.Value, MyTable.Text
How can i make a select which returns me all three fields, but not having the same MyTable.Value ?
"SELECT DISTINCT MyTable.Value FROM MyTable" returns only the column "MyTable.Value"
and
"SELECT MyTable.Value from MyTable group by MyTable.Value" also returns only the column "MyTable.Value"
But I need the MyTable.Text also in my selection.....
Regards
Eric
Ps: I have SQL 2008
I have a table "MyTable" with the fields: MyTable.Id, MyTable.Value, MyTable.Text
How can i make a select which returns me all three fields, but not having the same MyTable.Value ?
"SELECT DISTINCT MyTable.Value FROM MyTable" returns only the column "MyTable.Value"
and
"SELECT MyTable.Value from MyTable group by MyTable.Value" also returns only the column "MyTable.Value"
But I need the MyTable.Text also in my selection.....
Regards
Eric
Ps: I have SQL 2008
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Eric,
The requirement itself seems to elaborated a little more.
As per your data:
ID Value Text
1 10 ABC
2 10 XYZ
In this data you want all the three fields, but only one distinct value 10. Now you need to tell SQL Server that what you would like to have for [ID] and [Text] columns. Do you want Minimum value? Do you want Maximum value, or May be any other AGGREGATE value?
If you want Minimum value for [ID] and [Text] columns, then the query provided by Simon above is perfect.
But do consider, that minimum[ID] and minimum[Text] may not be picked from the same row. You could end up having [ID] from one row and [Text] from some other row.
The requirement itself seems to elaborated a little more.
As per your data:
ID Value Text
1 10 ABC
2 10 XYZ
In this data you want all the three fields, but only one distinct value 10. Now you need to tell SQL Server that what you would like to have for [ID] and [Text] columns. Do you want Minimum value? Do you want Maximum value, or May be any other AGGREGATE value?
If you want Minimum value for [ID] and [Text] columns, then the query provided by Simon above is perfect.
But do consider, that minimum[ID] and minimum[Text] may not be picked from the same row. You could end up having [ID] from one row and [Text] from some other row.
ASKER
Hello
Thanks for elaboration!!
Very good explanation!!
Eric
Thanks for elaboration!!
Very good explanation!!
Eric
ASKER
Thanks!