Results 1 to 7 of 7
Feb 11, 2011, 10:31 #1
- Join Date
- Nov 2006
- 0 Post(s)
- 0 Thread(s)
Detecting Inter-lapping Date Ranges
I have a table (shown below) that ideally if I could would make the companyid and the start and end dates unique in such a way that one can input the same companyid so long as the start and end dates do not overlap each other. I haven't found a way to make this possible so I am attempting to detect any possible user errors just to inform the user of invalid entries.
I've established several rules for this table, mainly :
1. EntryDate < ExpDate
2. Muiltiple ProspectCompanyID may not have intertwining EntryDate < ExpDate
Right now I'm just trying to see if I can detect these errors. Rule 1 was easy to find, but rule 2 is a tad bit more difficult.
Here is an example of my table:
CREATE TABLE IF NOT EXISTS `CompanyTitleHolder` ( `CompanyTitleHolderID` int(10) NOT NULL auto_increment, `CompanyID` int(10) NOT NULL, `MemberID` int(10) NOT NULL, `EntryDate` date NOT NULL, `ExpDate` date NOT NULL COMMENT 'Expiration Date', PRIMARY KEY (`CompanyTitleHolderID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Ownership Table';
Here is my first query which finds all the records where more than one entry is entered per companyID
My second query needs to iterate through each companyid from the first and manually check that dates are not over-lapping each other.
As you can tell the second part isn't very well fleshed out at this point. I was wondering if I could combine the two queries as I think* that querying a query is redundant if you do not plan to make many subqueries for a query... (perhaps I am wrong though)
Is there a way to take the start and end date from one row and compare them to other rows without splitting the query. and is it possible to iterate through each owner.
This is rather complex since I'm unable to express the idea very clearly so if you need more specification, don't hesitate to ask :P
P.S. If there is a simplier method, I will take those suggestions too.Please...Never describe anything to me using foo and bar.