SQL in MS Access - count the total number of times each field has a particular value?
-
Hi sorry if the title isn't clear - I'm not sure how to phrase it! I'm using MS Access SQL, and here is the code I would like to run: SELECT TOP 1 Members_Ex_Classes.Class_ID, (SELECT COUNT(["Liked?"]= "Y") FROM Non_Members_Ex_Classes) + (SELECT COUNT(["Liked?"] = "Y") FROM Members_Ex_Classes) AS [Total Number of Likes] FROM Members_Ex_Classes, Non_Members_Ex_Classes WHERE Members_Ex_Classes.["Liked?"] = "Y" or Non_Members_Ex_Classes.["Liked?"] = "Y" GROUP BY Members_Ex_Classes.Class_ID, Non_Members_Ex_Classes.Class_ID ORDER BY COUNT(Members_Ex_Classes.Class_ID) DESC I would like to display the total number of "Likes" the Class_ID with the most likes has from both the members_ex_classes and non_members_ex_classes tables. (The same class_ids are used in both tables) How can I change my code to make it work? Thanks
-
Answer:
you've got some messy code up here... probably clearer to set up actual subqueries. It would be useful if you post your database somewhere so we can download and test with it But check out the SQL command "HAVING", that might help you out. You have a field name with a question mark in it? first time I've seen that ["Liked?"]
S at Yahoo! Answers Visit the source
Related Q & A:
- How to count number of occurrences of pattern within a string?Best solution by Stack Overflow
- How to convert my SQL query to MS Access query?Best solution by Stack Overflow
- How to Count total number of Words in PDF?Best solution by Super User
- How to connect php file to ms access?Best solution by Stack Overflow
- How does the new LLC determine the total number of issuable shares?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.