我有两个名为report_instance和report_history的表(report_instance有很多report_history)。我想用report_history的前10条记录加入每个report_instance。如何将表1的每条记录加入表2的少量记录?
实施例:
report_instance r1 has 20 report_history
report_instance r2 has 5 report_history
查询应给我与前10个记录R 2与5 report_history 20 report_history和连接R1的结果。
我的查询:
select *
from report_instances ri, report_history rh
where ri.id in (select rhh.id
from report_history
where rhh.report_instance_id=ri.id limit 10);
我得到了错误:
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
当你的错误消息来自MySQL时,为什么这个问题用sqlserver标记? – Bohemian
意味着你只需要每个report_intance的前10个report_history ...是它.. –
@ZafarMalik是啊 –