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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:16:55+00:00 2026-06-07T09:16:55+00:00

I am having difficulty with writing an SQL query for my application. Below shows

  • 0

I am having difficulty with writing an SQL query for my application. Below shows a screenshot of some of the tables in my database.

enter image description here
enter image description here

Please let me explain how a section of my application works, and then I can show you the problem I am having with my SQL query.

A User can create an application form on my system (dbo.Form). An application form consists of several sections, one of those sections is Employment History (dbo.FormEmployment). An employment record includes details like employer name, start date etc, but also a gradeID. A User can add one or more employment records to the table dbo.FormEmployment.

A system administrator can add a Shift (dbo.Shift) to the system, and also then assign Grades to a Shift. These Grades are recorded in the dbo.ShiftGrade table. A Shift can be assigned 1 or more Grades, i.e. it could be assigned 1,2,3,4 or 5 Grades.

When the system administrator has added the Shift and Shift Grades, I then want to perform an SQL query to return a list of Users whose Grades match that of the Grades assigned to a Shift (remember the User adds their Grade when they add an employment record).

I have written the following SQL query which works, however, the issue with this query is that it returns a list of Users, that have any Grade that matches that of the Grades assigned to a Shift.

SELECT   u.userID, u.userTypeID, u.firstName, u.lastName, u.email, u.password, 
u.contactNumber, u.organisationID, u.emailVerificationCode, u.mobileVerificationCode, 
u.userStatusID, u.AddedBy, u.AddedDate, u.ModifiedBy, u.ModifiedDate
FROM     [User] u
--Check Grades Match
WHERE    u.userID IN
     (
     SELECT f.locumID
     FROM   dbo.Form f, dbo.FormEmployment emp
     WHERE  f.formID = emp.formID
     AND    emp.statusID = 101
     AND    emp.workYN = 1
     AND    emp.gradeID IN (
             select gradeID from dbo.ShiftGrade where shiftID = @p0
             )
     )

You can see I am using the IN statement to do this. However, I only want to return a list of Users who can match exactly the same Grades that have been assigned to a Shift. Therefore, if a Shift has been assigned 3 Grades, then I want a List of Users who also have the exact same three Grades to be returned.

I apologise for the lengthy post, I just thought it would be better explained this way.
Any feedback or help with this would be greatly appreciated.

  • 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-07T09:16:57+00:00Added an answer on June 7, 2026 at 9:16 am
    select u.*
    from dbo.Users u
    join dbo.Form f on u.? = f.formId
    join dbo.FormEmployment fe on fe.formId = f.formId
    join dbo.Grade g on g.gradeId =  fe.gradeId
    join dbo.ShiftGrade shg on shg.gradeId =g.gradeId
    join dbo.Shift sh on sh.shiftId = shg.shiftId
    where
        sh.shiftId = -- recently added shift id
    and g.gradeId == -- recently added grade id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some difficulty writing this code in php. I want to create a
I'm having some difficulty writing some Unit Tests to test a custom ModelBinder that
I'm writing a microsoft word macro and having difficulty with vb.net. Please help.
I'm having some difficulty with writing some jQuery code. What i'm trying to do
I am having some difficulty writing a function that will search through a directory
I'm having some difficulty writing a regular expression. My input will be a url,
I am having difficulty writing a Stored Procedure that will query a list of
I am having difficulty using carrierwave together mongoid. I am writing an application that
Im having difficulty trying to design a database structure for the following scenario: My
I am having difficulty creating sessions for my mobile application that is written in

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.