sql query with offset and limit
My database table contain "created_time" column.
I need to get only one record at a time based on the "created_time" column.
(starting from least date&time)
For that i wrote the query like
select * from table_name order by created_time limit 1 OFFSET 1
if i execute the query i am getting one record which has least time in database.
I need to write the query by increasing the offset value automatically?How to write the query?
mysql sql
add a comment |
My database table contain "created_time" column.
I need to get only one record at a time based on the "created_time" column.
(starting from least date&time)
For that i wrote the query like
select * from table_name order by created_time limit 1 OFFSET 1
if i execute the query i am getting one record which has least time in database.
I need to write the query by increasing the offset value automatically?How to write the query?
mysql sql
This appears to be a question about basic pagination
– Strawberry
Nov 22 '18 at 8:15
add a comment |
My database table contain "created_time" column.
I need to get only one record at a time based on the "created_time" column.
(starting from least date&time)
For that i wrote the query like
select * from table_name order by created_time limit 1 OFFSET 1
if i execute the query i am getting one record which has least time in database.
I need to write the query by increasing the offset value automatically?How to write the query?
mysql sql
My database table contain "created_time" column.
I need to get only one record at a time based on the "created_time" column.
(starting from least date&time)
For that i wrote the query like
select * from table_name order by created_time limit 1 OFFSET 1
if i execute the query i am getting one record which has least time in database.
I need to write the query by increasing the offset value automatically?How to write the query?
mysql sql
mysql sql
edited Nov 22 '18 at 7:20
Barbaros Özhan
12.6k71532
12.6k71532
asked Nov 22 '18 at 7:12
krishnakrishna
14
14
This appears to be a question about basic pagination
– Strawberry
Nov 22 '18 at 8:15
add a comment |
This appears to be a question about basic pagination
– Strawberry
Nov 22 '18 at 8:15
This appears to be a question about basic pagination
– Strawberry
Nov 22 '18 at 8:15
This appears to be a question about basic pagination
– Strawberry
Nov 22 '18 at 8:15
add a comment |
2 Answers
2
active
oldest
votes
You can write the query as below, no need to mention offset.
select * from table_name order by created_time limit 1
In this you are limiting the data to one record. The OFFSET argument is used to identify the starting point to return rows from a result set.
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
add a comment |
ASC or DESC by created_time?
select * from table_name order by created_time desc limit 1
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425601%2fsql-query-with-offset-and-limit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can write the query as below, no need to mention offset.
select * from table_name order by created_time limit 1
In this you are limiting the data to one record. The OFFSET argument is used to identify the starting point to return rows from a result set.
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
add a comment |
You can write the query as below, no need to mention offset.
select * from table_name order by created_time limit 1
In this you are limiting the data to one record. The OFFSET argument is used to identify the starting point to return rows from a result set.
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
add a comment |
You can write the query as below, no need to mention offset.
select * from table_name order by created_time limit 1
In this you are limiting the data to one record. The OFFSET argument is used to identify the starting point to return rows from a result set.
You can write the query as below, no need to mention offset.
select * from table_name order by created_time limit 1
In this you are limiting the data to one record. The OFFSET argument is used to identify the starting point to return rows from a result set.
answered Nov 22 '18 at 7:20
Aravind Bhat KAravind Bhat K
274214
274214
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
add a comment |
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Thanks for your response.If i execute the above query , i am getting same record every time.Which was not suitable to my problem.I need to get the record based on "created_time" column based on least time. means,i need to get 16th date then 17th date like that...
– krishna
Nov 22 '18 at 7:29
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Ok, can u give me a quick example?
– Aravind Bhat K
Nov 22 '18 at 7:33
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Suppose table contains records, 16-10-2018 , 17-10-2018 i need to get records by date.If i execute above query i am getting first record every time. second time i need to get second record(17th date). I think the query needs offset for this scenario?
– krishna
Nov 22 '18 at 7:50
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
Yes for this you need offset. I will edit my answer. In which language, you have the date variables
– Aravind Bhat K
Nov 22 '18 at 8:46
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
The date variables type is ZonedDateTime.
– krishna
Nov 23 '18 at 4:50
add a comment |
ASC or DESC by created_time?
select * from table_name order by created_time desc limit 1
add a comment |
ASC or DESC by created_time?
select * from table_name order by created_time desc limit 1
add a comment |
ASC or DESC by created_time?
select * from table_name order by created_time desc limit 1
ASC or DESC by created_time?
select * from table_name order by created_time desc limit 1
answered Nov 22 '18 at 7:28
Lion.ZLion.Z
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425601%2fsql-query-with-offset-and-limit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This appears to be a question about basic pagination
– Strawberry
Nov 22 '18 at 8:15