Jump to content

[SOLVED] self join and count


M.O.S. Studios

Recommended Posts

hey guys,

 

im trying to send a my sql query that return information about an invoice and return a row count as a column,

 

table format is

 

invoices:

client_name - invoice_number - [...] - `complete`

 

invoice_prod

 

ref - qty [...]

 

soo if invoice_number has 3 rows where ref = invoice_number the db will ander this

 

client_name    invoice_number  Complete    count(*)

peter griffin            1                  true          3

 

 

im not sure whats wrong with my code, any advice helps

 

 

SELECT `invoice_number`, `complete`, `invoice_prod`.count(*) FROM `invoices`, `invoice_prod` WHERE `invoices`.`index` = `invoice_prod`.`ref`
LIMIT 0 , 30

Link to comment
Share on other sites

how meny of each product they bought, how ever the count funcction just represents howmeny differn't products they bought

 

ie,

they bought

 

3 x apples

1 x orange

1 x juicer

 

incoice_pro would have 3 rows as follows:

 

ref - qty - name

1      3      apples

1      1      orange

1      1      juicer

 

 

the total would come out like this:

client_name    invoice_number  Complete    count(*)

peter griffin            1                  true          3

 

 

p.s. can mysql do the math of how meny total products?

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.