If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Howto select the next free date?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-04, 10:37
tREXX tREXX is offline
Registered User
 
Join Date: Jul 2004
Posts: 4
Howto select the next free date?

I have a table that has an int (kind of a foreign key) and a date as primary key. Simplified it looks like this:
Code:
memberpages:
----------------------------
| member_id | page_created |
----------------------------
| 1         | 2004-03-14   |
| 1         | 2004-03-13   |
| 1         | 2004-03-11   |
----------------------------
Ok - i'm using mySQL 3.23.49 (which doesn't support sub selects) and i try to do a query, that selects from a defined date on the next unused date in the past.

So if 2004-03-14 is the defined date, the query should output 2004-03-12.

Anyone has an idea how to do this? I've already tried to join the table with itself but i couldn't get an useful output from that. The ugly way would be to do a loop in PHP until it selects a count(*) = 0. But i'd prefer to avoid that.

Any help is appreciated. Thanks,
tREXX
Reply With Quote
  #2 (permalink)  
Old 07-19-04, 11:52
iaguigon iaguigon is offline
Registered User
 
Join Date: May 2004
Location: Barcelona, Spain
Posts: 54
Hi!

Can't try this myself, but might help you:

select a.page_created defined, a.page_created - 1 unused
from memberpages a, memberpages b
where a.page_created > b.page_created
and page_created = 'your date'
group by 1
having a.page_created-1 > max(b.page_created)

regards
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On