Select * from article order by postdate desc limit 0, 1
The above line shows the query in the first row data
I now want to query line 1 line 8 line 15 data at the same time, need how to write?
CodePudding user response:
The first line: select * from article order by postdate desc limit 1;
Line 8: select * from article order by postdate desc limit 7, 1;
Line 15: select * from article order by postdate desc limit, 1;
CodePudding user response:
reference response: 1/f friendship dream the first line: select * from article order by postdate desc limit 1; Line 8: select * from article order by postdate desc limit 7, 1; Line 15: select * from article order by postdate desc limit, 1; This I tried the query time is accumulative, are there any other way to line the query can handle it! CodePudding user response:
On the basis of the above brother connect using UNION Select * from article order by postdate desc limit 1 The union Select * from article order by postdate desc limit 7, 1 The union Select * from article order by postdate desc limit, 1; CodePudding user response:
Parentheses, or you will quote syntax error (select * from testlimit limit 1) The union (select * from testlimit limit 7, 1) The union (select * from testlimit limit of 14, 1); CodePudding user response:
The reference 4 floor response: friendship dream add parentheses, or you will quote grammar (select * from testlimit limit 1) The union (select * from testlimit limit 7, 1) The union (select * from testlimit limit of 14, 1); Above, put inside the PHP function or an error in the database directly query is no problem, have no other ways to link operator? I just need to display the specified a few rows of data, CodePudding user response:
reference 5 floor tandingyu reply: Quote: refer to 4th floor response: friendship dream Parentheses, or you will quote syntax error (select * from testlimit limit 1) The union (select * from testlimit limit 7, 1) The union (select * from testlimit limit of 14, 1); Above, put inside the PHP function or an error in the database directly query is no problem, have no other ways to link operator? I just need to display the specified a few rows of data, Should only this way, the other seems not support to do this, you look at the PHP function to what wrong, database, no problem CodePudding user response:
SELECT * The FROM ( SELECT (@ I:=@ I + 1) AS the num, A. * The FROM (SELECT * FROM article ORDER BY postdate DESC) a, (SELECT @ I:=0) AS it ) A WHERE A.n um IN (1, 8) CodePudding user response:
Why use this way of query? If you have inserted or deleted? CodePudding user response:
You found out 1 to 15 rows of data, use the code to pick up to the three rows of data it is easy to solve ah