Skip to content
Advertisement

Why do these two SQL queries return a different number of rows?

If I execute the following query in Workbench, I get back the expected number of rows — 5.

JavaScript

However if I enter the same user_id in the search field of my web app it returns ALL orders, whether or not it has been refunded, but still lists the total number of refunds as 5.

JavaScript

Any help is appreciated.

Advertisement

Answer

Because you need to add all the or clauses inside parenthesis like this.

JavaScript

In your own implementation, you either need a row to be refunded with a specific id, or have a specific user id or a specific transaction id.

So the query returned all the user related rows, regardless of whether or not they were refunded.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement