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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현