Optimize query of mysqlHow to output MySQL query results in CSV format?How do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?Optimize 2 mysql queries to oneHow to get a list of user accounts using the command line in MySQL?Optimize SQL QueryHow to reset AUTO_INCREMENT in MySQL?How do I import an SQL file using the command line in MySQL?MySQL Query to select between 2 datesOptimizing MySQL query with multiple joins and Sub query

Wordplay subtraction paradox

Why doesn't philosophy have higher standards for its arguments?

What "fuel more powerful than anything the West (had) in stock" put Laika in orbit aboard Sputnik 2?

Interviewing with an unmentioned 9 months of sick leave taken during a job

Why does "git status" show I'm on the master branch and "git branch" does not in a newly created repository?

How could an animal "smell" carbon monoxide?

What is the difference between a Hosaka, Ono-Sendai, and a "deck"?

Why does FFmpeg choose 10+20+20 ms instead of an even 16 ms for 60 fps GIF images?

Intel 8080-based home computers

ROT13 encoder/decoder

Is it ethical for a company to ask its employees to move furniture on a weekend?

Random piece of plastic

What are "full piece" and "half piece" in chess?

Was Jacobi the first to notice the ambiguity in the partial derivatives notation? And did anyone object to his fix?

Kepler space telescope undetected planets

Strategy to pay off revolving debt while building reserve savings fund?

Increasing muscle power without increasing volume

Pi 3 B+ no audio device found

Is this Android phone Android 9.0 or Android 6.0?

My credit card has no magnetic stripe. Is this a problem in the USA?

How to make a plagal cadence sound convincing as an ending?

Is straight-up writing someone's opinions telling?

Get node ID or URL in Twig on field level

what relax command means?



Optimize query of mysql


How to output MySQL query results in CSV format?How do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?Optimize 2 mysql queries to oneHow to get a list of user accounts using the command line in MySQL?Optimize SQL QueryHow to reset AUTO_INCREMENT in MySQL?How do I import an SQL file using the command line in MySQL?MySQL Query to select between 2 datesOptimizing MySQL query with multiple joins and Sub query






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















In current scenario, My Database store each user order item, Where one order have multiple items and all items will have same orderNumber. I am not much experienced in mysql. But I had modified the default search query to get the order by auditTimestamp. As user can edit order items, Which will update the single product auditTimestamp.



I have created an inner query earlier to iterate all orders and then group by them, After that get their latest auditTimestamp using MAX function. Currently I need to optimize it. below is the sample. Where I need to optimize the inner join.



select
distinct ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,maxaudit.maxaudittimestamp as maxaudittimestamp
from
ORDER as ORD
INNER JOIN (select
ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,MAX(ORD1.AUDITTIMESTAMP) maxaudittimestamp
from
ORDER ORD1
where
ORD1.USERID = 1 AND
ORD1.STATUS IN ('Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void')
GROUP BY
ORD1.ORDERNUMBER) maxaudit
on maxaudit.ORDERID = ORD.ORDERID
WHERE
WAR.ORDERID = 1) ORRDATA
WHERE 1 = 1 AND
,ORDER.SEQ = 1
ORDER BY
ORRDATA.maxaudittimestamp DESC;


As Result I need to get All orde by user and sort them by latest first. But whose primary order of seq = 1, status should be 'Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void'



Optimisation required to replace










share|improve this question

















  • 1





    Wondering how this can be working as "ORDER" is a reserved word and you don't quote it

    – B001ᛦ
    Mar 26 at 9:18






  • 1





    Make your live easier . Dont use reseverd keyword for schemas and fieldnames

    – Bernd Buffen
    Mar 26 at 9:45











  • @B001ᛦ real query is working fine, this is just an dummy example. The real object is to optimise the inner query with inner join, When I try to use inner join, so while writting group by it gives error. So am stuck .

    – SurendraKumar Jaiswal
    Mar 26 at 10:38

















0















In current scenario, My Database store each user order item, Where one order have multiple items and all items will have same orderNumber. I am not much experienced in mysql. But I had modified the default search query to get the order by auditTimestamp. As user can edit order items, Which will update the single product auditTimestamp.



I have created an inner query earlier to iterate all orders and then group by them, After that get their latest auditTimestamp using MAX function. Currently I need to optimize it. below is the sample. Where I need to optimize the inner join.



select
distinct ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,maxaudit.maxaudittimestamp as maxaudittimestamp
from
ORDER as ORD
INNER JOIN (select
ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,MAX(ORD1.AUDITTIMESTAMP) maxaudittimestamp
from
ORDER ORD1
where
ORD1.USERID = 1 AND
ORD1.STATUS IN ('Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void')
GROUP BY
ORD1.ORDERNUMBER) maxaudit
on maxaudit.ORDERID = ORD.ORDERID
WHERE
WAR.ORDERID = 1) ORRDATA
WHERE 1 = 1 AND
,ORDER.SEQ = 1
ORDER BY
ORRDATA.maxaudittimestamp DESC;


As Result I need to get All orde by user and sort them by latest first. But whose primary order of seq = 1, status should be 'Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void'



Optimisation required to replace










share|improve this question

















  • 1





    Wondering how this can be working as "ORDER" is a reserved word and you don't quote it

    – B001ᛦ
    Mar 26 at 9:18






  • 1





    Make your live easier . Dont use reseverd keyword for schemas and fieldnames

    – Bernd Buffen
    Mar 26 at 9:45











  • @B001ᛦ real query is working fine, this is just an dummy example. The real object is to optimise the inner query with inner join, When I try to use inner join, so while writting group by it gives error. So am stuck .

    – SurendraKumar Jaiswal
    Mar 26 at 10:38













0












0








0








In current scenario, My Database store each user order item, Where one order have multiple items and all items will have same orderNumber. I am not much experienced in mysql. But I had modified the default search query to get the order by auditTimestamp. As user can edit order items, Which will update the single product auditTimestamp.



I have created an inner query earlier to iterate all orders and then group by them, After that get their latest auditTimestamp using MAX function. Currently I need to optimize it. below is the sample. Where I need to optimize the inner join.



select
distinct ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,maxaudit.maxaudittimestamp as maxaudittimestamp
from
ORDER as ORD
INNER JOIN (select
ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,MAX(ORD1.AUDITTIMESTAMP) maxaudittimestamp
from
ORDER ORD1
where
ORD1.USERID = 1 AND
ORD1.STATUS IN ('Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void')
GROUP BY
ORD1.ORDERNUMBER) maxaudit
on maxaudit.ORDERID = ORD.ORDERID
WHERE
WAR.ORDERID = 1) ORRDATA
WHERE 1 = 1 AND
,ORDER.SEQ = 1
ORDER BY
ORRDATA.maxaudittimestamp DESC;


As Result I need to get All orde by user and sort them by latest first. But whose primary order of seq = 1, status should be 'Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void'



Optimisation required to replace










share|improve this question














In current scenario, My Database store each user order item, Where one order have multiple items and all items will have same orderNumber. I am not much experienced in mysql. But I had modified the default search query to get the order by auditTimestamp. As user can edit order items, Which will update the single product auditTimestamp.



I have created an inner query earlier to iterate all orders and then group by them, After that get their latest auditTimestamp using MAX function. Currently I need to optimize it. below is the sample. Where I need to optimize the inner join.



select
distinct ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,maxaudit.maxaudittimestamp as maxaudittimestamp
from
ORDER as ORD
INNER JOIN (select
ORDER.ORDERID
,ORDER.ORDERNUMBER
,ORDER.CREATIONDATE
,ORDER.STATUS
,ORDER.AUDITTIMESTAMP
,ORDER.USERID
,ORDER.SEQ
,MAX(ORD1.AUDITTIMESTAMP) maxaudittimestamp
from
ORDER ORD1
where
ORD1.USERID = 1 AND
ORD1.STATUS IN ('Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void')
GROUP BY
ORD1.ORDERNUMBER) maxaudit
on maxaudit.ORDERID = ORD.ORDERID
WHERE
WAR.ORDERID = 1) ORRDATA
WHERE 1 = 1 AND
,ORDER.SEQ = 1
ORDER BY
ORRDATA.maxaudittimestamp DESC;


As Result I need to get All orde by user and sort them by latest first. But whose primary order of seq = 1, status should be 'Active'
,'CANCELLED'
,'OUT FOR DELIVERY'
,'Void'



Optimisation required to replace







mysql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 9:16









SurendraKumar JaiswalSurendraKumar Jaiswal

10914 bronze badges




10914 bronze badges







  • 1





    Wondering how this can be working as "ORDER" is a reserved word and you don't quote it

    – B001ᛦ
    Mar 26 at 9:18






  • 1





    Make your live easier . Dont use reseverd keyword for schemas and fieldnames

    – Bernd Buffen
    Mar 26 at 9:45











  • @B001ᛦ real query is working fine, this is just an dummy example. The real object is to optimise the inner query with inner join, When I try to use inner join, so while writting group by it gives error. So am stuck .

    – SurendraKumar Jaiswal
    Mar 26 at 10:38












  • 1





    Wondering how this can be working as "ORDER" is a reserved word and you don't quote it

    – B001ᛦ
    Mar 26 at 9:18






  • 1





    Make your live easier . Dont use reseverd keyword for schemas and fieldnames

    – Bernd Buffen
    Mar 26 at 9:45











  • @B001ᛦ real query is working fine, this is just an dummy example. The real object is to optimise the inner query with inner join, When I try to use inner join, so while writting group by it gives error. So am stuck .

    – SurendraKumar Jaiswal
    Mar 26 at 10:38







1




1





Wondering how this can be working as "ORDER" is a reserved word and you don't quote it

– B001ᛦ
Mar 26 at 9:18





Wondering how this can be working as "ORDER" is a reserved word and you don't quote it

– B001ᛦ
Mar 26 at 9:18




1




1





Make your live easier . Dont use reseverd keyword for schemas and fieldnames

– Bernd Buffen
Mar 26 at 9:45





Make your live easier . Dont use reseverd keyword for schemas and fieldnames

– Bernd Buffen
Mar 26 at 9:45













@B001ᛦ real query is working fine, this is just an dummy example. The real object is to optimise the inner query with inner join, When I try to use inner join, so while writting group by it gives error. So am stuck .

– SurendraKumar Jaiswal
Mar 26 at 10:38





@B001ᛦ real query is working fine, this is just an dummy example. The real object is to optimise the inner query with inner join, When I try to use inner join, so while writting group by it gives error. So am stuck .

– SurendraKumar Jaiswal
Mar 26 at 10:38












0






active

oldest

votes










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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353459%2foptimize-query-of-mysql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353459%2foptimize-query-of-mysql%23new-answer', 'question_page');

);

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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript