Is thios correct to count a distinct value in field?
SELECT COUNT(DISTINCT(CAR)) FROM CAR_S
have error
SYNTAX sql...
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SYNTIAX sql...
In SQL Server, you could use
SELECT COUNT(DISTINCT CAR) FROM CAR_S
but Microsoft Access doesn't support this syntax. You can use the following instead:
SELECT COUNT(CAR) FROM (SELECT DISTINCT CAR FROM CAR_S)
or
SELECT COUNT(CAR) FROM (SELECT CAR FROM CAR_S GROUP BY CAR)
SELECT COUNT(DISTINCT CAR) FROM CAR_S
but Microsoft Access doesn't support this syntax. You can use the following instead:
SELECT COUNT(CAR) FROM (SELECT DISTINCT CAR FROM CAR_S)
or
SELECT COUNT(CAR) FROM (SELECT CAR FROM CAR_S GROUP BY CAR)
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4369
- Joined: 26 Apr 2010, 17:36
Re: SYNTIAX sql...
HansV wrote:In SQL Server, you could use
SELECT COUNT(DISTINCT CAR) FROM CAR_S
but Microsoft Access doesn't support this syntax. You can use the following instead:
SELECT COUNT(CAR) FROM (SELECT DISTINCT CAR FROM CAR_S)
or
SELECT COUNT(CAR) FROM (SELECT CAR FROM CAR_S GROUP BY CAR)
TKS!
work.
But in order of speeding, peraph a group by and count have the best result, or not?
-
- Administrator
- Posts: 78622
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: SYNTIAX sql...
You'd have to test it on a large table. I think the difference will be small.
Best wishes,
Hans
Hans