Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order by Clause conflicts with distinct in access?

Tags:

sql

ms-access

Please help me with this as I have been unable to get past this problem

When trying to execute this statement:

SELECT distinct grade
FROM tblStudents
ORDER BY Val([grade]),grade;

access tells me that ORDER BY clause Val([grade]) conflicts with Distinct

How can I fix this?

Thank you in advance

like image 540
Kevin Avatar asked Jul 18 '11 14:07

Kevin


People also ask

Can you use distinct with ORDER BY?

Without a transformation, a statement that contains both DISTINCT and ORDER BY would require two separate sorting steps-one to satisfy DISTINCT and one to satisfy ORDER BY. (Currently, Derby uses sorting to evaluate DISTINCT. There are, in theory, other ways to accomplish this.)

Is distinct better or group by?

DISTINCT is used to filter unique records out of all records in the table. It removes the duplicate rows. SELECT DISTINCT will always be the same, or faster than a GROUP BY. In the following table duplicate records are present.

Can you use distinct and ORDER BY in SQL?

There is no way this query can be executed reasonably. Either DISTINCT doesn't work (because the added extended sort key column changes its semantics), or ORDER BY doesn't work (because after DISTINCT we can no longer access the extended sort key column).


1 Answers

You cannot order by a column thats not listed in a select distinct statement; if you want grade coerced to an integer;

SELECT DISTINCT Val([grade])
FROM tblStudents
ORDER BY Val([grade]);
like image 183
Alex K. Avatar answered Sep 23 '22 02:09

Alex K.