1
lenmore 2014-01-23 18:38:14 +08:00
SQL Server可以这样写的,减少一半IO:
SELECT * FROM tbl_a CROSS APPLY (SELECT TOP (1) name, detail FROM tbl_b WHERE id1=tbl_a.id1 AND id2=tbl_a.id2 ORDER BY date DESC) AS T WHERE id1='1' |
2
cxe2v 2014-01-23 21:00:30 +08:00
我能看出来的也就是楼上那种,把后面两个括号里的select写成一句
|
4
yangqi 2014-01-23 22:47:46 +08:00
你这不就是一个简单的Join么?还是我理解错了?
SELECT tbl_a.*, tbl_b.name, tbl_b.detail FROM tbl_a JOIN tbl_b ON tbl_b.id1 = tbl_a.id1 AND tbl_b.id2 = tbl_a.id2 WHERE tbl_a.id1='1' ORDER BY tbl_b.date DESC LIMIT 1 |
5
cjjer 2014-01-24 00:32:09 +08:00
|
7
yangqi 2014-01-24 00:47:54 +08:00
|
8
mechille OP |