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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:21:55+00:00 2026-05-11T10:21:55+00:00

I have three tables: computers, which has columns for id, serial number, make, model,

  • 0

I have three tables:

 computers, which has columns for id, serial number, make, model, etc users, which has columns for id, real name computer_usage, which has columns id, computer_id, user_id, start_date, end_date 

The database records all computers that we have, our users, and who used what computer when.

I want to run a query that selects all computers that do not have a current user.

This would be:

There is a computer_id that doesn’t exist at all within computer_usage or There is a computer_id that does exist within computer_usage that has an end_date of

What is the best way of selecting those records?

  • 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. 2026-05-11T10:21:55+00:00Added an answer on May 11, 2026 at 10:21 am

    Try this:

    SELECT *  FROM computers  WHERE id NOT IN      (SELECT computer_id       FROM computer_usage      WHERE end_date is NULL) 

    The subquery shows you all computers that are currently in use (a record exists, so we assume it has a start_date, but no end_date has been assigned).

    I’m assuming here that the end_date doesn’t get populated until the ‘usage’ is complete. If that isn’t correct (if the end dates are pre-assigned, for example), then just do:

    SELECT *  FROM computers  WHERE id NOT IN      (SELECT computer_id       FROM computer_usage      WHERE start_date < getDate()      AND end_date > getDate()) 

    The subquery still shows all computers that are currently ‘on assignment’. Just find all computers not in that group. (Note that I’ve used ‘getDate’, which is a MS SQL function. I think the mysql equivalent is something having to do with TIMESTAMP.)

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

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Globalisation in ASP.NET should do everything for you pretty much.… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer You will probably need to wrap calls to either the… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer If you look at how Microsoft defines it's winapi handles… May 11, 2026 at 6:00 pm

Related Questions

I have a webpage on my site that displays a table, reloads the XML
Bear in mind here, I am not an Access guru. I am proficient with
I made an FPS game with MSVC++ which is running very well on Windows.
What's the technical term for a computer-friendly name of an entity: e.g. Guns N'

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.