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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-27 : 09:04:46
|
| chock writes "Hai ,i am getting the correct result for the below queryrs.Open "SELECT DISTINCT RepTL From PEList WHERE RepFL='" & CriteriaName & "'", Cnn, adOpenStatic, adLockReadOnly, adCmdTextbut the thing is i need to display the record in the Order by RepId, but when i add RepId in the query its shows more records and not the distinct RepTL when i write as belowrs.Open "SELECT DISTINCT RepTL,RepId From PEList WHERE RepFL='" & CriteriaName & "'", Cnn, adOpenStatic, adLockReadOnly, adCmdTextwhat is the way to display the records order by Id and the RepTL should be distinct.Kindly suggest me.Thank you,Chock. " |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-27 : 14:12:52
|
| don't use DISTINCT, use group by, and then add a MIN(Order) or MAX(order) expression to your query.Never just add DISTINCT clauses to your queries to make the results "look right" -- you must understand logically the data you are querying and if you want certain results displayed, you must write the proper SQL to get it -- usually by using a GROUP BY or querying the proper table or remove unnecessary joins.- Jeff |
 |
|
|
|
|
|
|
|