Skip to content
Advertisement

sql find parent table where sum of child column not equal to parent column

hey guys i am trying to find the a bill from billMaster where the sum of billDetails.total is not equal to billMaster.remainingAmount

NB this is a one to many relationship where one bill can contain more billdetails

i tried the below query and got an sql error

both queries returned the same error i gess its on how i used the sum on where close. But the sad thing is that i cant sole the problem.. Any response will be appreciated.

now assume i want to get recent user bill that meets the above condition . Note the billMaster has a column called user_id. how will the new query look like.

Advertisement

Answer

Thank you every one for your feedback it led me to the correct path and the modified query is

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