Skip to content
Advertisement

Query to return one result, but have a count of other field

I have multiple fields within my SQL table(Microsoft Access) and have created a form that will allow users to search for a serial number. This search should use the value of a text box to search one field(Serial Number), but return the serial number, model of said serial number, description of said serial number and then a count of how many models are the same as the model of the serial number.

Here is the code I’ve been working with, it will run, but returns a logical error.

e.g. I’m searching for the serial number 00220, I hit the search button and it returns. The value of the count should be two(There is a total quantity of two S320 models), but it’s just returning the number of results found and not the total number of models that match.

Any help with this issue would be greatly appreciated!

Edit: Found the solution with the help of user: @GMB

Advertisement

Answer

You could JOIN the table with an aggregate subquery that counts the number of occurences of each model, like:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement