我尝试加入两个表:
SELECT E . * , D . *
FROM `basicincident` E
LEFT JOIN incident D ON E.`INC_KEY` = D.`INC_KEY`
WHERE E.`STATE` = "MD"
AND SUBSTRING( E.INC_DATE , -4 ) = "2009"
LIMIT 0 , 10
它产生了良好的结果。
但是使用时order by
,需要更长的时间才能产生结果。
SELECT E . * , D . *
FROM `basicincident` E
LEFT JOIN incident D ON E.`INC_KEY` = D.`INC_KEY`
WHERE E.`STATE` = 'MD'
AND SUBSTRING( E.INC_DATE , -4 ) = '2009'
AND E.INC_KEY >"MD0100110520090000015011111"
ORDER BY E.INC_KEY limit 0,2