[英]MySQL select first 5 rows (multiple rows)
我需要在MySQL中選擇多行。 我有一個名為“ proc_table”的過程,該過程現在返回3個字段-oid,objet和db.cars中的1行。 查詢受到限制(由我限制)。
我需要刪除該限制並進行查詢,這將返回我的前5行。 如果它們不存在,將沒有引用(具有空值的字段)。 我用“偽代碼”進行查詢。
問:我應該使用MySQL中的哪個函數來選擇特定的行? 如果不存在,該如何處理?
CREATE procedure `proc_table`()
BEGIN
SELECT a.oid as 'oid',
a.objet as 'objet',
-- limited query
(select tab2_oid from db.cars where tab1_oid = a.oid LIMIT 1)
-- limited query
FROM db.tab1 as a;
END$$
-- limited query
(select tab2_oid as 'first_row' from db.cars where tab1_oid = a.oid where row=1)
(select tab2_oid as 'second_row' from db.cars where tab1_oid = a.oid where row=2)
...
-- limited query
如何使用聯合和LIMIT語句?
select feld1,feld2 from
( select feld1,feld2 from table1 where... LIMIT 1,1
union all
select feld1,feld2 from table2 where....LIMIT 2,1
....
)a LIMIT 5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.