Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:53:49+00:00 2026-06-15T07:53:49+00:00

I have to create a MySQL Query for a report. I have a table

  • 0

I have to create a MySQL Query for a report.

I have a table history which keeps record of status changes of a product’s order. I have these statuses for an order’s life cycle (the flow of an order): new, confirmed, processing, shipped, delivered, cancelled, returned. An order doesn’t necessarily follow this status flow, for example: A new order can be cancelled immediately, or it can be cancelled while in processing. This makes the accurate reporting more complex.

Now I want to make a Supply Chain report of orders which were confirmed, processed, shipped and then delivered. But this report should exclude orders which were cancelled at any stage or returned.

Consider this example:

An order (id: 34) was placed by a customer. Initial status: New. Confirmed by an Agent, status set to Confirmed. Supply Chain manager verifies availability, status changes to Processing, then shipped and then delivered.

Another order (id: 55) comes, New, confirmed, processing but cancelled. history looks like:

id  order_id status
111 34       new
112 34       confirmed
113 55       new
114 55       confirmed
115 55       processing
116 34       processing
117 55       cancelled
118 34       shipped
119 34       delivered

How do I make a report query to get only those orders which were

  1. Confirmed, Processed, shipped and delivered.
  2. Confirmed, processed, cancelled.
  3. confirmed, cancelled
  4. and so on…

How can I write a query to get these kinds of reports?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:53:51+00:00Added an answer on June 15, 2026 at 7:53 am

    for new order:select distinct(order_id) from history where status = new
    for new processed:select distinct(order_id) from history where status = processed
    and so on

    for those order which are new, processed and delivered

    select t1.order_id from history as t1, history as t2, history as t3 where t1.order_id=t2.order_id and t2.order_id=t3.order_id and t1.status=new and t2.status = processed and t3.status = delivered

    like this go on for others

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to create a script that takes a mySQL table, and exports it
Let's assume that I have mytable in mySQL CREATE TABLE `mytable` ( `gender` enum('MALE','FEMALE','UNISEX')
I have 2 tables in my mysql database: CREATE TABLE IF NOT EXISTS `RECIPES`
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a mysql legacy table which contains an client identifier and a list
We have an PHP/MySQL application where the users can create their own databases, which
I have mysql table with data like this. record will have server with total
I'm using PHP/MySQL and I have to create a new table from an existing
I have a basic hosting package that gives me access to create a MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.