看看这两个查询:
简单的:
mysql> SELECT * FROM omgbatch JOIN omgoutput ON (idomgbatch=omgbatch) WHERE idomgoutput = (SELECT DISTINCT lastoutput FROM omgenvelope WHERE lastinput=18658); +------------+-------+------------+------- ------+---------+----------+ | idomgbatch | 芦丁 | 批处理时间 | idmgoutput | 流量模式 | omgbatch | +------------+-------+------------+------- ------+---------+----------+ | 12174 | 8 | 20140508040930-832 | 10728 | 162 | 12174 | +------------+-------+------------+------- ------+---------+----------+ 1 行(0.00 秒)
和
复杂的:
mysql> SELECT * FROM omgbatch JOIN omgoutput ON (idomgbatch=omgbatch) WHERE idomgoutput IN (SELECT DISTINCT lastoutput FROM omgenvelope WHERE lastinput=18658); +------------+-------+------------+------- ------+---------+----------+ | …