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 805161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:02:25+00:00 2026-05-15T00:02:25+00:00

I have three tables (these are the relevant columns): Table1 bookingid, person, role Table2

  • 0

I have three tables (these are the relevant columns):

Table1
bookingid, person, role


Table2
bookingid, projectid


Table3
projectid, project, numberofrole1, numberofrole2

Table1.role can take two values: “role1” or “role2”.

What I want to do is to show which projects don’t have the correct number of roles in Table1. The number of roles there there should be for each role is in Table3.

For example, if Table1 contains these three rows:

bookingid, person, role
7, Tim, role1
7, Bob, role1,
7, Charles, role2

and Table2

bookingid, projectid
7, 1

and Table3

projectid, project, numberofrole1, numberofrole2
1, Test1, 2, 2

I would like the results to show that there are not the correct number of role2s for project Test1.

To be honest, something like this is a bit beyond my ability, so I’m open to suggestions on the best way to do this. I’m using sqlite and php (it’s only a small project). I suppose I could do something with the php at the end once I’ve got my results, but I wondered if there was a better way to do it with sqlite.

I started by doing something like this:

SELECT project, COUNT(numberofrole1) as "Role"
FROM Table1
JOIN Table2
USING (projectid)
JOIN Table3
USING (bookingid)
WHERE role="role1"
GROUP BY project

But I can’t work out how to compare the value returned as “Role” with the value got from numberofrole1

Any help is gratefully received.

  • 1 1 Answer
  • 3 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-05-15T00:02:26+00:00Added an answer on May 15, 2026 at 12:02 am

    try this:

    Select * From Table3 t3
    Where (Select Count(*) From Table1 t1r1
              Join Table2 t2r1 On t2r1.bookingid = t1r1.bookingid
           Where t2r1.projectid = t3.ProjectId
              And role = 'role1') <>  numberofrole1 
         Or
         (Select Count(*) From Table1 t1r2
              Join Table2 t2r2 On t2r2.bookingid = t1r2.bookingid
           Where t2r2.projectid = t3.ProjectId
              And role = 'role2') <>  numberofrole2
    

    or even better, if it works… (try it)

    Select * From Table3 t3
    Where Exists 
          (Select * From Table1 t1r1
              Join Table2 t2r1 
                   On t2r1.bookingid = t1r1.bookingid
           Where t2r1.projectid = t3.ProjectId
           Group By Role
           Having Sum(Case Role When 'role1' Then 1 Else 0 End) 
                                  = t3.numberofrole1
              And Sum(Case Role When 'role2' Then 1 Else 0 End)  
                                  = t3.numberofrole2 ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables (lots in reality but these three are the ones I
I have users table. There are three other tables: developers, managers, testers. All of
I have EF 4 implemented in the project. Within it, there are tables customer
I have to admin there is slight difference between the columns from both tables.
If I have three columns in my MySQL table people , say id, name,
I have two tables, House and Person . For any row in House, there
I have two database tables, 'Lists' and 'Notes'. Lists has columns _id, listname Notes
I have date range data in SQL DB table that has these three (only
I have three tables: `brands` (`id`, `name`) `categories` (`id`, `name`) `products` (`id`, `name`, `brand_id`,
I have two tables that have the same columns. If a change occurs it

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.