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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:20:33+00:00 2026-06-03T02:20:33+00:00

I am a total SQL noob; sorry. I have a table mysql> describe activity;

  • 0

I am a total SQL noob; sorry.

I have a table

mysql> describe activity;
+--------------+---------+------+-----+---------+-------+
| Field        | Type    | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| user         | text    | NO   |     | NULL    |       |
| time_stamp   | int(11) | NO   |     | NULL    |       |
| activity     | text    | NO   |     | NULL    |       |
| item         | int     | NO   |     | NULL    |       |
+--------------+---------+------+-----+---------+-------+

Normally activity is a two-step process; 1) “check out” and 2 “use”

An item cnnot be checked out a second time, unless used.

Now I want to find any cases where an item was checked out but not used.

Being dumb, I would use two selects, one for check out &one for use, on the same item, then compare the timestamps.

Is there a SELECT statemnt that will help me selct the items which were checked out but not used?

Tricky with the possibility of multipel checkouts. Or should I just code

loop over activity, form oldest until newset
  if find a checkout and there is no newer used time then i have a hit 
  • 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-03T02:20:35+00:00Added an answer on June 3, 2026 at 2:20 am

    You could get the last date of each checkout or use and then compare them per item:

    SELECT MAX(IF(activity='check out', time_stamp, NULL)) AS last_co, 
    MAX(IF(activity='use', time_stamp, NULL)) AS last_use
    FROM activity
    GROUP BY item
    HAVING NOT(last_use >= last_co);
    

    The NOT(last_use >= last_co) is written that way because of how NULL compare behaviour works: last_use < last_co will not work if last_use is null.

    Without proper indexing, this query will not perform very well though. Plus you might want to bound the query using a WHERE condition.

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

Sidebar

Related Questions

How to loop update total field in procedures in SQL Server? I have table
I have very little experience with MySQL/SQL in general - total n00b really! I
I have a sql table which has five columns Count1 float Count2 float Total
I have a total of three sql commands running on one connection. When the
Hi I have following sql statement that gives me the the first_name and total
Sorry because this is a noob question. I'm new with MySQL: I wrote a
table: postid|userid|post|replyto post sql SELECT * FROM table WHERE postid=12 total replies sql SELECT
I have created a SQL Server 2005 matrix with a total column. I want
I am trying to pull the total number of rows in a SQL table.
I have an SQL statement that counts over the total number of rows active

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.