0

Hello I have been working with a project to MySQL database and I am converting it to MS ACCESS database.

Can someone help me for the equivalent of this query from MySQL to MS ACCESs SQL? Becouse my ms access query does not work.

The MySQL Query :

Select count(u.phone) as ordernr, u.firstname , u.lastname , u.address from user u join orders o on u.phone = o.phone group by firstname ;

MS ACCESS Query (is not working) which i tryed so far:

Select count(u.phone) as ordernr, u.firstname as firstname, u.lastname as lastname , u.address as add from user u inner join orders o on u.phone = o.phone group by firstname ;

is giving me this error message : your query does not include the specified expression 'lastname' as part of an aggregate function.

Looking forward for your help and/or suggestions! Thank you

2 Answers 2

2

The correct MS Access version is:

Select count(u.phone) as ordernr, u.firstname, u.lastname, u.address
from [user] as u inner join
     orders as o
     on u.phone = o.phone
group by u.firstname, u.lastname, u.address;

Note:

  • user is a reserved word in MS Access.
  • join operation needs to include the inner.
  • as is needed for table aliases.
  • The group by needs to include all columns (that is a SQL-thing true of all databases except MySQL).
Sign up to request clarification or add additional context in comments.

7 Comments

@HasS . . . I just updated the answer. I think I have all the access'isms accounted for.
Hmm it worked , thanks a lot for your help, i have many other queries that i want to convert and this helped a lot :) @Gordon Linoff
if you can help me on this one too , im getting a strange behaviour , and I think there is nothing wrong with this query : Select i.itemname, i.id, i.price as pricexitem,oil.quantity , (oil.quantity * i.price) as price from orders as o inner join orderitemlist as oil on oil.orderid = o.id inner join item as i on i.id = oil.itemid where o.id= 2 ;
Minor correction: Access SQL does not require the AS keyword for table aliases.
@HasS - That is a different issue. Please ask a new question.
|
2

You have to include in the GROUP BY clause every non-aggregated field present in the SELECT clause:

Select count(u.phone) as ordernr, 
       u.firstname as firstname, 
       u.lastname as lastname , 
       u.address as addr 
from user u 
inner join orders o on u.phone = o.phone
group by firstname, lastname, addr ;

1 Comment

Hello giorgos , thank you for your answer, the query you wrote is not working maybe becose 'user' is reserved from the ms access and it needs to be [user] but all the other parts of query is totally ok . Best regards

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.