How to get several specific records from a query result?How to Perform Two Simple Queries using Select Value...
Is the percentage symbol a constant?
How to transport 10,000 terrestrial trolls across ocean fast?
Why is it that Bernie Sanders always called a "socialist"?
Using functions like sine, cosine and tangent to calculate coordinates in Tikz
When does a person lose diplomatic status?
Boss asked me to sign a resignation paper without a date on it along with my new contract
What is the meaning of "usr"?
Plotting Laguerre Gaussian beam intensity in transverse and line profile via center?
Coworker asking me to not bring cakes due to self control issue. What should I do?
Manager has noticed coworker's excessive breaks. Should I warn him?
Are one-line email responses considered disrespectful?
How can I differentiate duration vs starting time
How to deal with an underperforming subordinate?
Tikz: Perpendicular FROM a line
How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?
How can I handle players killing my NPC outside of combat?
Is there a way to pause a running process on Linux systems and resume later?
What is an efficient way to digitize a family photo collection?
What is the smallest molar volume?
Minimum Viable Product for RTS game?
How do I make my single-minded character more interested in the main story?
Create a line break in a subscript-position term
Is Screenshot Time-tracking Common?
Why is Shelob considered evil?
How to get several specific records from a query result?
How to Perform Two Simple Queries using Select Value from First QueryOptimized query to fetch a record from 10 million entriesIs it possible that records are changed while a read query is still executing?Query where there are only two rows with specific datahow to get a sorted result from mysql query?Get a specific number of rows from parent table?OFFSET using a GUID kind of IDRetrieving specific results from a queryQuery not returning result if the join fails (how to get it to return zero)MySQL - can't get the result of non-matching records
I know by using Like with "LIMIT 1, OFFSET x" I can get the Xth record from a returned query result. But what if I want to get X, Y, and Z all at once?
Currently I do a for loop and it's like I'm doing this:
SELECT record from table LIMIT 1, OFFSET X
SELECT record from table LIMIT 1, OFFSET Y
SELECT record from table LIMIT 1, OFFSET Z
But I want something like this:
SELECT record from table LIMIT 3, OFFSET X, Y, and Z
This is because I think it is more efficient to get X, Y, Zth records in one query execution than in multiple ones.
mysql
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I know by using Like with "LIMIT 1, OFFSET x" I can get the Xth record from a returned query result. But what if I want to get X, Y, and Z all at once?
Currently I do a for loop and it's like I'm doing this:
SELECT record from table LIMIT 1, OFFSET X
SELECT record from table LIMIT 1, OFFSET Y
SELECT record from table LIMIT 1, OFFSET Z
But I want something like this:
SELECT record from table LIMIT 3, OFFSET X, Y, and Z
This is because I think it is more efficient to get X, Y, Zth records in one query execution than in multiple ones.
mysql
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Never useLIMIT
withoutORDER BY
. Unless you don't care about which rows are chosen.
– ypercubeᵀᴹ
May 15 '15 at 10:01
add a comment |
I know by using Like with "LIMIT 1, OFFSET x" I can get the Xth record from a returned query result. But what if I want to get X, Y, and Z all at once?
Currently I do a for loop and it's like I'm doing this:
SELECT record from table LIMIT 1, OFFSET X
SELECT record from table LIMIT 1, OFFSET Y
SELECT record from table LIMIT 1, OFFSET Z
But I want something like this:
SELECT record from table LIMIT 3, OFFSET X, Y, and Z
This is because I think it is more efficient to get X, Y, Zth records in one query execution than in multiple ones.
mysql
I know by using Like with "LIMIT 1, OFFSET x" I can get the Xth record from a returned query result. But what if I want to get X, Y, and Z all at once?
Currently I do a for loop and it's like I'm doing this:
SELECT record from table LIMIT 1, OFFSET X
SELECT record from table LIMIT 1, OFFSET Y
SELECT record from table LIMIT 1, OFFSET Z
But I want something like this:
SELECT record from table LIMIT 3, OFFSET X, Y, and Z
This is because I think it is more efficient to get X, Y, Zth records in one query execution than in multiple ones.
mysql
mysql
edited May 14 '15 at 21:51
Adé
asked May 14 '15 at 21:38
AdéAdé
112
112
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 16 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Never useLIMIT
withoutORDER BY
. Unless you don't care about which rows are chosen.
– ypercubeᵀᴹ
May 15 '15 at 10:01
add a comment |
Never useLIMIT
withoutORDER BY
. Unless you don't care about which rows are chosen.
– ypercubeᵀᴹ
May 15 '15 at 10:01
Never use
LIMIT
without ORDER BY
. Unless you don't care about which rows are chosen.– ypercubeᵀᴹ
May 15 '15 at 10:01
Never use
LIMIT
without ORDER BY
. Unless you don't care about which rows are chosen.– ypercubeᵀᴹ
May 15 '15 at 10:01
add a comment |
2 Answers
2
active
oldest
votes
If the X,Y,and Z are sequential you can use this:
SELECT record from table LIMIT X,3
Limit is not the best way of writing queries since it produces the entire query result set and send back only the number of rows specified (Version 5.5 MySQL). If you can use the primary key to look up the rows, include X,Y,and Z primary key in Where
clause.
add a comment |
SELECT record from table LIMIT 1, OFFSET X
UNION
SELECT record from table LIMIT 1, OFFSET Y
UNION
SELECT record from table LIMIT 1, OFFSET Z
Make them UNION ALL
if you know that X,Y,Z are different or don't care if there are dups. The default is UNION DISTINCT
, which does an extra pass to dedup.
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fdba.stackexchange.com%2fquestions%2f101559%2fhow-to-get-several-specific-records-from-a-query-result%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
If the X,Y,and Z are sequential you can use this:
SELECT record from table LIMIT X,3
Limit is not the best way of writing queries since it produces the entire query result set and send back only the number of rows specified (Version 5.5 MySQL). If you can use the primary key to look up the rows, include X,Y,and Z primary key in Where
clause.
add a comment |
If the X,Y,and Z are sequential you can use this:
SELECT record from table LIMIT X,3
Limit is not the best way of writing queries since it produces the entire query result set and send back only the number of rows specified (Version 5.5 MySQL). If you can use the primary key to look up the rows, include X,Y,and Z primary key in Where
clause.
add a comment |
If the X,Y,and Z are sequential you can use this:
SELECT record from table LIMIT X,3
Limit is not the best way of writing queries since it produces the entire query result set and send back only the number of rows specified (Version 5.5 MySQL). If you can use the primary key to look up the rows, include X,Y,and Z primary key in Where
clause.
If the X,Y,and Z are sequential you can use this:
SELECT record from table LIMIT X,3
Limit is not the best way of writing queries since it produces the entire query result set and send back only the number of rows specified (Version 5.5 MySQL). If you can use the primary key to look up the rows, include X,Y,and Z primary key in Where
clause.
edited May 15 '15 at 3:20
answered May 15 '15 at 2:41
MasoudMasoud
440514
440514
add a comment |
add a comment |
SELECT record from table LIMIT 1, OFFSET X
UNION
SELECT record from table LIMIT 1, OFFSET Y
UNION
SELECT record from table LIMIT 1, OFFSET Z
Make them UNION ALL
if you know that X,Y,Z are different or don't care if there are dups. The default is UNION DISTINCT
, which does an extra pass to dedup.
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
add a comment |
SELECT record from table LIMIT 1, OFFSET X
UNION
SELECT record from table LIMIT 1, OFFSET Y
UNION
SELECT record from table LIMIT 1, OFFSET Z
Make them UNION ALL
if you know that X,Y,Z are different or don't care if there are dups. The default is UNION DISTINCT
, which does an extra pass to dedup.
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
add a comment |
SELECT record from table LIMIT 1, OFFSET X
UNION
SELECT record from table LIMIT 1, OFFSET Y
UNION
SELECT record from table LIMIT 1, OFFSET Z
Make them UNION ALL
if you know that X,Y,Z are different or don't care if there are dups. The default is UNION DISTINCT
, which does an extra pass to dedup.
SELECT record from table LIMIT 1, OFFSET X
UNION
SELECT record from table LIMIT 1, OFFSET Y
UNION
SELECT record from table LIMIT 1, OFFSET Z
Make them UNION ALL
if you know that X,Y,Z are different or don't care if there are dups. The default is UNION DISTINCT
, which does an extra pass to dedup.
edited May 15 '15 at 3:44
answered May 14 '15 at 22:11
Rick JamesRick James
42.9k22259
42.9k22259
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
add a comment |
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
I just tried profiling using unions like this (using union all too). It was slow; individual queries would have been faster.
– Adé
May 15 '15 at 4:40
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- 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%2fdba.stackexchange.com%2fquestions%2f101559%2fhow-to-get-several-specific-records-from-a-query-result%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
Never use
LIMIT
withoutORDER BY
. Unless you don't care about which rows are chosen.– ypercubeᵀᴹ
May 15 '15 at 10:01