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

  • Home
  • SEARCH
  • 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 9194089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:19:21+00:00 2026-06-17T21:19:21+00:00

I use this query to get all sales from yesterday. To export this somewhere.

  • 0

I use this query to get all sales from yesterday. To export this somewhere.
Since there are a lot of cancelled, pending payment, processing and so on, I thought to export only the ones that are completed.

But somehow mysql just ignoes the fist where restriction.
I get all the sales all the time. It doesn’t matter what i write in.
It only has to be a state that was used yesterday.

$sql = '

SELECT
        sales_flat_order_grid.entity_id,
        sales_flat_order_grid.increment_id AS increment_id,
        sales_flat_order_grid.quote_id AS quote_id,
        sales_flat_order_grid.store_name AS store_name,
        sales_flat_order_grid.created_at AS created_at,
        sales_flat_order_grid.billing_name AS billing_name,
        sales_flat_order_grid.payment_method AS payment_method,
        sales_flat_order_grid.grand_total AS grand_total,
        sales_order_status.label AS status,
        sales_flat_order_item.sku AS sku,
        sales_flat_order_item.name AS name,
        sales_flat_order_item.price_incl_tax AS price_incl_tax,
        sales_flat_order_item.product_options AS product_options,
        sales_flat_order_payment.additional_information AS additional_information

FROM
        sales_flat_order_grid,
        sales_order_status,
        sales_flat_order_item,
        sales_flat_order_payment

WHERE
        sales_flat_order_grid.status = "Complete"
        AND sales_flat_order_grid.entity_id = sales_flat_order_item.order_id
        AND sales_flat_order_grid.entity_id = sales_flat_order_payment.entity_id
        AND sales_flat_order_grid.created_at >= "' . $date . ' 00:00:00"
        AND sales_flat_order_grid.created_at <= "' . $date . ' 23:59:59"

ORDER BY
        sales_flat_order_grid.entity_id DESC

';
  • 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-17T21:19:22+00:00Added an answer on June 17, 2026 at 9:19 pm

    You’re setting yourself up for disaster when you write queries like this:

    FROM
        sales_flat_order_grid,
        sales_order_status,
        sales_flat_order_item,
        sales_flat_order_payment
    
    WHERE
        sales_flat_order_grid.status = "Complete"
        AND sales_flat_order_grid.entity_id = sales_flat_order_item.order_id
        AND sales_flat_order_grid.entity_id = sales_flat_order_payment.entity_id
        AND sales_flat_order_grid.created_at >= "' . $date . ' 00:00:00"
        AND sales_flat_order_grid.created_at <= "' . $date . ' 23:59:59"
    

    Why? Because it’s too easy to miss a JOIN condition.

    Instead, use this syntax:

    FROM
        sales_flat_order_grid
        INNER JOIN sales_order_status ON ....
        INNER JOIN sales_flat_order_item ON sales_flat_order_grid.entity_id = sales_flat_order_item.order_id
        INNER JOIN sales_flat_order_payment ON sales_flat_order_grid.entity_id = sales_flat_order_payment.entity_id
    
    WHERE
        sales_flat_order_grid.status = "Complete"
        AND sales_flat_order_grid.created_at >= "' . $date . ' 00:00:00"
        AND sales_flat_order_grid.created_at <= "' . $date . ' 23:59:59"
    

    See the .... there? It’s missing a join condition and therefore it selects a cartesian product instead. Add the missing join condition and your results should be more in line with your expectations.

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

Sidebar

Related Questions

I want to use this SQL query to get only the records between 8
In my query I want to get all users of the same city. This
I'm using this query to get all employees of {clients with name starting with
The object of my query is to get all rows from table a where
Maybe it's wrong but I always use this query for my app: cme_only =
I am trying to use this MySQL query: SET @a:=0; UPDATE tbl SET sortId=@a:=@a+1
The answer to another SO question was to use this SQL query: SELECT o.Id,
I use this function substr(tbarticles.articlebody,1,200) as description1 in a query but for some articles
now i use this code: $welcome_text = mysql_query(SELECT * FROM `text` WHERE `name` =
I need to rewrite this query and I'm not allowed to use a subquery.

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.