我有兩個名爲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是啊 –