0

We have 50 tables we need to query a column that exists in all. This column is a checkbox. We need to count per table how many are checked and how many are unchecked. Cant seem to get 1 query to count results and display per table as opposed to multiplying or combining results. We need 1 column per table to display count of checked and unchecked. Thanks

SELECT "Table1" , Count('qcpass') AS column 
    FROM 5000028 
    GROUP BY [5000028].qcpass
union 
SELECT "Table2",count('qcpass')
    FROM 5000029 
    Group By [5000029].qcpass;
0

2 Answers 2

1

Edit

Based on your feedback, try this (sorry, didn't realize you wanted 1 column per table):

  1. Make a union query that combines all 50 tables. The result should be 1 row per table:

    SELECT "5000028" as QCPASS, Count () FROM 5000028 group by QCPASS
    UNION
    SELECT "5000029" as QCPASS, Count () FROM 5000029 group by QCPASS
    UNION...

  2. Now make a "Crosstab" query which is pretty easy in Access. First, make a new query and select the Crosstab option at the top. This query will use the union query as its source.

  3. This will have 3 columns. The first will be a constant value (you can use "Totals" if you like, it's just a placeholder). Set this as your "Row Heading".

  4. The 2nd column will be QCPass. Set this as your "Column Heading".

  5. The 3rd column will be Expr1. Set this as your "Value".

When you run this, you should see a 1-row table with 1 column per each of your source tables.

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

8 Comments

SELECT QCPASS AS 5000028, Count () FROM 5000028 group by QCPASS UNION SELECT QCPASS AS 5000029, Count () FROM 5000029 group by QCPASS This counts but puts everything in 1 row - I need 1 column per table.. Thanks Greatly for the help
Hi User, I edited my post, but it's actually incomplete. As is, it only gives you the total number of checkboxes in each table. What is the name of your checkbox?
Thanks for the response - The below seems to output the result separately per table in a row - which is ok - but my next challenge is to get only records in a date range from a DATETIME column in each of the 50 tables: SELECT "okok" AS Expr1, Count('qcpass') AS w FROM 5000028 GROUP BY [5000028].qcpass union SELECT "op",count('qcpass') as i FROM 5000029 Group By qcpass;
Can you edit your post and add your code there? It's unreadable in the comments like that. Thanks.
SELECT "Table1" , Count('qcpass') AS column FROM 5000028 GROUP BY [5000028].qcpass union SELECT "Table2",count('qcpass') FROM 5000029 Group By [5000029].qcpass;
|
0
SELECT columna, 'tablename1' from tablename1 where ..
UNION
SELECT columna, 'tablename2' from tablename2 where ..
UNION
SELECT columna, 'tablename3' from tablename3 where ..
...
SELECT columna, 'tablename4' from tablename50 where .. 

1 Comment

I need to count the checked and unchecked rows.

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.