Jump to content

To many iterations of value in MySQL Query


imperium2335

Recommended Posts

Hi,

 

I am having problems with the following query:

 

$result = mysql_query("SELECT DATE(invoices_out.invoiceDate) AS date,
				  invoices_out.jobRef,
				  invoices_out.branch,
				  invoices_out.customer, 
				  invoices_out.currency, 
				  invoices_out.absoluteTotal, 
				  invoices_out.euroVpound, 
				  invoices_out.dollarVpound,
				  sum(if(pos.currency = '$', pos.amount/pos.dollarRate, 0))+sum(if(pos.currency = '€', pos.amount/pos.euroRate, 0))+sum(if(pos.currency = '£', pos.amount, 0)) AS totalCosts,
				  enquiries.theirShippingTotal,
				  enquiries.theirShippingCurrency,
				  pourbaskets.coreCreditBuy,
				  pourbaskets.shippingTotal,
				  pourbaskets.currency,
				  pourbaskets.shippingCurrency,
				  partbaskets.coreCreditSell
				  FROM invoices_out, pos, enquiries, pourbaskets, partbaskets
				  WHERE pos.jobRef = invoices_out.jobRef
				  AND enquiries.id = invoices_out.enqRef
				  AND pourbaskets.enquiryRef = invoices_out.enqRef
				  AND partbaskets.enquiryRef = invoices_out.enqRef
				  GROUP BY invoices_out.jobRef, pos.jobRef, pourbaskets.enquiryRef, partbaskets.enquiryRef")or die(mysql_error()) ;

 

It seems to be adding up totalCosts for every instance of a row that has the same enquiryRef in partbaskets. If I take partbaskets and pourbaskets out of the entire query, it returns the right value.

 

What am I missing?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.