Mysql query giving incorrect values [closed]

Posted on

Question :

When this SQL query is executed it gives incorrect value, please advise

from cash_management inner join order_master 
where cash_management.cashier_name=order_master.cashier_name   
and date(date)='2015-02-19' 
and date(order_time)='2015-02-19' 

Answer :

Without knowing what data you are starting with in each table, what is being produced and what is wrong/what you expected – I can only make some general observations to help you:

1)Code Formatting – Format your code better, use table aliases to shorten your code or at least tidy it up a bit. You will find it easier to read and therefore debug.

2)At a guess, could it be your WHERE caluse at fault? If this is a sales ledger, are “date” and “order_time” always going to be the same date? If a record is inserted into a table and then a field is updated, you may find that the double WHERE is excluding records that you want included.

3)Since you have a join going on – do the required records (an order master record and a corresponding cash management record) exist on both tables?

As I said, no data and no examples so I can’t help – but these are my starters for 10.

Leave a Reply

Your email address will not be published. Required fields are marked *