以下是4種會產生重疉的情況
(ns, ne, es, ee) = (new_start, new_end, existing_start, existing_end):
- ns - ne - es - ee: doesn't overlap and doesn't match (because ne < es)
- ns - es - ne - ee: ovarlaps and matches
- es - ns - ee - ne: ovarlaps and matches
- es - ee - ns - ne: doesn't overlap and doesn't match (because ns > ee)
- es - ns - ne - ee: ovarlaps and matches
- ns - es - ee - ne: ovarlaps and matches
SQL 語法 以下搜尋的版本
SQL Statment
Below method is found from internet while the second method is my own way usally use.
SELECT * FROM tbl WHERE
existing_start BETWEEN '$newStart' AND '$newEnd' OR
existing_end BETWEEN '$newStart' AND '$newEnd' OR
'$newStart' BETWEEN existing_star AND existing_end
以下是的個人慣常的做法, 兩者皆可找出重疊的紀錄
SELECT * FROM tbl WHERE
( existing_start<='$newStart' AND existing_end>'$newStart' )
AND ( existing_start<'$newEnd' AND existing_start>'$newStart' )