Results 1 to 2 of 2

Thread: Need help with a really tough SQL query

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    3

    Post

    All right. I've been playing with this all day so far and I haven't gotten anywhere. I'm hoping there's an SQL guru out there who can help me out.

    This may sound really wierd, but this is what I need...

    I am building a database to keep track of our server backup scheme and which tape was used for each backup. I thought it would be nice for the program to pick which tape should be used on any given day. It should choose the tape that was used least recently. So basically, what I have is this.

    A table with TapeId and DateUsed

    1 4
    2 5
    3 6
    4 7
    1 8
    2 9
    3 10
    4 11
    1 12

    Now, in real life, the TapeId is not as simple as 1,2,3,4 (also pretend that the second column is a date, I just didn't want to type in a bunch of dates). So it's easy to look at the above table and see that the next tape to use should be 2 because from

    2 9
    3 10
    4 11
    1 12

    Tape 2 has the oldest date. Now I have created the query using the MAX function to get this result set. I just can't seem to get the minimum of this set. Can anyone PLEASE help? I stumped our SQL guy here with this one and I don't have much hair left to pull out.

    Thanks,
    Castor

  2. #2
    Junior Member
    Join Date
    Sep 1999
    Location
    Rock Island
    Posts
    21

    Post

    Why not just try this?
    SELECT TapeID, DateUsed
    FROM tblTape
    ORDER BY DateUsed

    This will set the first record in your recordset as the latest date. In this order

    TapeID DateUsed
    6 4/23/98
    1 4/23/98
    2 8/8/98
    5 1/1/99
    4 9/10/99
    3 10/1/99

    Now the only problem I can see is if( as in my table) you have many Dates that are the same. Tell me if this helps


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width