select date from 表2 left join 表1 on table2.id1=table1.id1 and table2.name2=table1.name1
...... 认真点好不好 首先,select max(date) from table2错了,max是group by 子句的函数。 其次这个需要4.1以上的mysql支持(我现在这个不支持) 再次,你这种写法“where date = (select max(date) from table2) ”就大错特错了。最后,这种方法会影响速度,是个全表查询,如果有几十万的数据是不是很浪费资源。不过我也想不出更好的了。。
select table1.*,table2.* from table1 left join table2 on table1.id1=table2.id1 where date = (select max(date) from table2)
to xwqjamky(陌上烟花): 老大,您的就免了
sorry,关于 max的用法我说错了,呵呵,道歉道歉
select name1,name2 from table1 left join table2 order by id2 desc on table1.id1=table2.id1 limit 0,1 就是反序取出第一条 有没有这种写法,呵呵
不知道这样的方法怎么样 select * from table1 where id1 exist ( select id1 from table2 where date = (select top 1 date from table2 order by date) as a )
select name1,name2 from table1 left join table2 on table1.id1=table2.id1 order by id2 desc limit 0,1
认真点好不好
首先,select max(date) from table2错了,max是group by 子句的函数。
其次这个需要4.1以上的mysql支持(我现在这个不支持)
再次,你这种写法“where date = (select max(date) from table2)
”就大错特错了。最后,这种方法会影响速度,是个全表查询,如果有几十万的数据是不是很浪费资源。不过我也想不出更好的了。。
老大,您的就免了
就是反序取出第一条
有没有这种写法,呵呵
select *
from table1
where id1 exist
(
select id1
from table2
where date =
(select top 1 date
from table2
order by date)
as a
)