select * from article order by postdate desc limit 0,1
上面這行顯示的是查詢第一行的資料
我現在想同時查詢第1行 第8行 第15行的資料,需要怎么寫?
uj5u.com熱心網友回復:
第一行:select * from article order by postdate desc limit 1;第八行:select * from article order by postdate desc limit 7,1;
第15行:select * from article order by postdate desc limit 14,1;
uj5u.com熱心網友回復:
這種我試過 查詢時間是累加的,有沒有其它辦法 一行查詢陳述句能搞定的!
uj5u.com熱心網友回復:
在上面老哥的基礎上 使用 UNION 進行連接select * from article order by postdate desc limit 1
union
select * from article order by postdate desc limit 7,1
union
select * from article order by postdate desc limit 14,1;
uj5u.com熱心網友回復:
加上括號,不然會報語法錯誤(select * from testlimit limit 1)
union
(select * from testlimit limit 7,1)
union
(select * from testlimit limit 14,1);
uj5u.com熱心網友回復:
以上放PHP函式里邊還是報錯,在資料庫直接查詢是沒問題。 有沒有不用鏈接符的其它辦法? 我只需要顯示指定的幾行資料就行。
uj5u.com熱心網友回復:
應該只有這方法了,其他貌似不支持這樣做,你看看PHP函式報啥錯,資料庫沒問題
uj5u.com熱心網友回復:
SELECT
*
FROM
(
SELECT
( @i := @i + 1 ) AS num,
a.*
FROM
( SELECT * FROM article ORDER BY postdate DESC ) a,
( SELECT @i := 0 ) AS it
) A
WHERE
A.num IN ( 1, 8 )
uj5u.com熱心網友回復:
為什么要用這種查詢方式?如果有插入或者洗掉呢?uj5u.com熱心網友回復:
你查出來1到15行資料 ,用代碼再取想要的這三行資料就很容易解決了啊
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113213.html
標籤:Web 開發
