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

  • Home
  • SEARCH
  • 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 8232415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:49:43+00:00 2026-06-07T17:49:43+00:00

I have a complex domain structure: User: id, name, email Team: id, name UserTeam:

  • 0

I have a complex domain structure:

User:        id, name, email
Team:        id, name
UserTeam:    id, user_id, team_id
Session:     id, data
UserSession: id, user_id, session_id
TeamSession: id, team_id, session_id
Scan:        id, user_id, session_id, test_data

I can invite users to take a “session”. A user can take a session (one UserSession is made) and if completed, the result is stored in a Scan. I can also invite a complete team, so one TeamSession is created and for every team member, a UserSession is made.

Now I want to perform the query: give me all the scans not yet performed (so I can remember users to take one). For this case, I want to select all usersessions and join scans where the scan id is NULL. I thought this was the way to find out a row from a joining table is not present yet.

This was my query:

SELECT us.id as userSessionId,
       sc.id as scanId,
       s.id as sessionId,
       u.id, u.name

FROM usersessions us
     LEFT JOIN sessions s ON us.session_id = s.id
     LEFT JOIN scans sc   ON us.session_id = sc.session_id
     LEFT JOIN users u    ON us.user_id = u.id

WHERE sc.id IS NULL

GROUP BY us.id

However, it does not work: nothing is returned while at least one user has not performed a scan yet. If I remove the WHERE clause to see what the data is, I get this back:

userSessionId  scanId  sessionId  id  name
45             45      39         39  John
46             45      39         40  Jane
47             45      39         41  Tom
48             45      39         42  Mark

In this case, all are in the same group and got a session (#39). Their user ids and user session ids are correct. Mark has not performed a scan. John did scan #45 (for Jane it was #46 and Tom #47).

If I add a where clause WHERE sc.user_id=u.id, I get the correct three results (scans #45, #46 and #47) but then Mark is missing. That’s the only one I want to grab in the end! If you change it then to both clauses WHERE sc.user_id=u.id AND sc.id IS NULL it (obviously now) returns nothing again.

What’s the query to get all user sessions NOT connected to a scan?

  • 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-07T17:49:45+00:00Added an answer on June 7, 2026 at 5:49 pm

    You can try this solution. If it works for you, I will edit my post to add an explanation:

    SELECT
        a.id AS userSessionId,
        b.id AS scanId,
        a.session_id AS sessionId,
        a.user_id,
        c.name
    FROM
    (
        SELECT a.*
        FROM usersessions a
        LEFT JOIN scans b ON a.user_id = b.user_id AND a.session_id = b.session_id
        WHERE b.id IS NULL
    ) a
    INNER JOIN
    (
        SELECT id, session_id
        FROM scans
        GROUP BY id, session_id
    ) b ON a.session_id = b.session_id
    INNER JOIN
        users c ON a.user_id = c.id
    

    I’m assuming your data looks something like this:

    usersessions:
    id  |  uid  |  session_id
    -------------------------
    45  |   39  |   39
    46  |   40  |   39
    47  |   41  |   39
    48  |   42  |   39
    
    
    scans:
    id  |  uid  |  session_id
    -------------------------
    45  |  39   |  39
    45  |  40   |  39
    45  |  41   |  39
    

    In which case you should end up with:

    userSessionId  |  scanId  |  sessionId  |  user_id  |  name
    -----------------------------------------------------------
    48             |  45      |  39         |  42       |  Mark
    

    Let me know if your scans table is allowed to look something like:

    scans:
    id  |  uid  |  session_id
    -------------------------
    45  |  39   |  39
    45  |  40   |  39
    45  |  41   |  39
    46  |  39   |  39
    46  |  40   |  39
    46  |  41   |  39
    46  |  42   |  39
    

    ^ In which case my query would not work, and would need to be rewritten (and I know how).

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

Sidebar

Related Questions

I have several complex data structures like Map< A, Set< B > > Set<
I have a data set that is in the format 100 domain bacteria phylum
We are using builder pattern to generate test data. These domain objects have relations
I have a pretty complex domain entities. I want to have lazy loading for
I have the following domain, a dossier with documents: -Dossier(Name,Documents[]) -Document(Name) Now there is
I have complex GUI application written in Python and wxPython. I want it to
I am using WCF and REST, and I have complex types, which are working
I have some complex message to show inside of a flash message so instead
We have a complex app that serves AJAX JSON streams (using ADO to grab
I have a complex RIA client that communicates with a WCF SOAP web service,

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.