2 messages in com.mysql.lists.mysqlHelp on query joining a 3rd table
FromSent OnAttachments
pedro mpa29 Jan 2006 10:24 
pedro mpa29 Jan 2006 11:11 
Subject:Help on query joining a 3rd table
From:pedro mpa (mail@sapo.pt)
Date:01/29/2006 10:24:17 AM
List:com.mysql.lists.mysql

Hello!

I am building a query to get a monthly total for receipts and receipts plus TAX. My problem is the TAX, it can be different for each receipt. I need help on including and relating each TAX value/id with each receipt, like receipt_items.price * 1.21 etc.

The tables are like the following example:

Table receipts: id | id_tax | date 1 1 2005-12-31 2 1 2006-01-01 3 2 2006-01-25 ... Table receipt_items: id | id_receipt | price (exc tax) 1 1 1000 2 2 1000 ... Table tax: id | tax (%) 1 19 2 21

So far I have:

SELECT SUM(receipt_items.price) AS total , (SUM(receipt_items.price) * [-help here-]) AS total_plus_tax FROM receipt_items, receipts WHERE receipt_items.id_receipt = receipts.id AND MONTH(receipts.date)=".$month." AND YEAR(receipts.date)=".$year."

Thanks in advance. Pedro.