0

I get an error message

Syntax error (missing operator) in query expression 'r = row_number() over (partition by ACell order by ACell desc)'

in Microsoft Access; I don't know why, but it works in Microsoft SQL Server.

My query:

select * 
from 
    (select *, r = row_number() over (partition by ACell order by ACell 
    desc) 
    from cellTB) a 
where 
    r <= 5;

Please could anyone help me?

Example Data: cellTB

=================
ACell  |   RNC
=================
1      |   1
-----------------
1      |   2
-----------------
1      |   3
-----------------
1      |   4 
-----------------
1      |   5
-----------------
1      |   6
-----------------
2      |   1
-----------------
2      |   2
-----------------
2      |   3
-----------------
2      |   4
-----------------
2      |   5
-----------------
2      |   6

I want to select just top 5 from duplicate ACell in MC Access.

4
  • 1
    Is this a pass-through query sent to SQL Server? If not, the syntax isn't correct, as Access doesn't support window functions Commented Feb 25, 2019 at 6:38
  • I don't know how to user these command 'r = row_number() over (partition by ACell order by ACell desc)' in Access. Commented Feb 25, 2019 at 7:03
  • Edit question to show sample data and desired output. Do you need an Access query object? Commented Feb 25, 2019 at 7:37
  • @June7 I have already input the example data and output that I want from this query. Commented Feb 26, 2019 at 4:33

2 Answers 2

1

You code is T-SQL. For Access SQL you can, for example, use my RowNumber function as previously posted several times:

Sequential row numbers

Sign up to request clarification or add additional context in comments.

Comments

1

MS Access doesn't support row_number() (just one of many reasons to switch to another database). One method to do what you want uses a correlated subquery:

select c.* 
from cellTB as c
where (select count(*)
       from cellTb as c2
       where c2.Acell = c.Acell and
             c2.id <= c.id  -- this is the primary key column
      ) <= 5;

This assumes that your table has a primary key, which is called id in this example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.