Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:50:36+00:00 2026-06-12T01:50:36+00:00

I have tables called: activities and deficiencies . activities table contains all activities registered

  • 0

I have tables called: activities and deficiencies.

activities table contains all activities registered by students. deficiencies table contains all deficiencies that the students might get due to the registered activity.

Here are the table structures with sample data:

activities table

activityid  title
-------------------------------------------------------------
1           Student Retreat
2           Student Orientation

deficiencies table

deficiencyid    activity_id     deficiency      status
-------------------------------------------------------------
1               1               NARRATION       CLEARED
2               1               PHOTO           CLEARED
3               1               REPORT          CLEARED
4               2               NARRATION       WAITING
5               2               PHOTO           CLEARED
6               2               REPORT          WAITING

For each activity entry, there will be three rows in the deficiencies table. I want to be able to list each activity once if all the statuses of the items listed there are already CLEARED. So if one or more is still WAITING – they don’t get listed in the query.

I was attempting to do this using this query but I couldn’t get any lucky:

SELECT * FROM deficiencies,activities WHERE status='CLEARED' AND activityid=activity_id AND COUNT(deficiencyid)=3 GROUP BY activity_id ORDER BY deficiencyid ASC

I was getting the following from MySQL:

Invalid use of group function

The output I was expecting is the first record in the activities table.

What could be the best solution using only one query without multiple SELECT in SELECT in another SELECT sub-queries? There will be thousands of records in the tables so I’m hoping that the most efficient query can be used.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:50:37+00:00Added an answer on June 12, 2026 at 1:50 am

    If you want to do this with a JOIN:

     SELECT A.activityid, A.title FROM activities A INNER JOIN deficiencies D 
        ON A.activityid = D.activityid WHERE D.status = 'CLEARED'
        GROUP BY A.activityID, A.title HAVING COUNT(*) = 3
    

    This JOINs the activity and deficiencies tables, filters out the records other than CLEARED, groups by activity, and the filters out the groups that do not have exactly three records in them.

    It requires that the data is guaranteed to be as you described it (always three deficiency records). I wrote the GROUP BY to avoid using the MySQL extension allowing non-grouped, non-aggregated columns to be selected. Also, I assume that there’s also a studentid field involved which you left out for the sake of clarity, otherwise this whole system will support only a single student.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables called A and B . Table A contains request details
Hey, I have a tables called downloads, and in that table it stores the
I have a table called Activities and for each activity I can have zero
I have two tables: servers and stats servers has a column called id that
I have some tables. These tables all have one column in common called 'classified_id':
I have 2 tables called login and Roles . In the login table, I
I have three tables called: users , facilities , and staff_facilities . users contains
I have two tables called Reviews and Levels. CREATE TABLE [dbo].[Reviews]( [ReviewID] [int] IDENTITY(1,1)
I have two tables called 'events' and 'topics' each table can have many comments.
I have a table called as Activity with columns like activity_id and activity_date .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.