M.O.S. Studios Posted May 31, 2009 Share Posted May 31, 2009 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 https://forums.phpfreaks.com/topic/160393-solved-self-join-and-count/ Share on other sites More sharing options...
Ken2k7 Posted May 31, 2009 Share Posted May 31, 2009 What does qty in invoice_prod represent? Link to comment https://forums.phpfreaks.com/topic/160393-solved-self-join-and-count/#findComment-846395 Share on other sites More sharing options...
M.O.S. Studios Posted May 31, 2009 Author Share Posted May 31, 2009 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 https://forums.phpfreaks.com/topic/160393-solved-self-join-and-count/#findComment-846397 Share on other sites More sharing options...
Ken2k7 Posted May 31, 2009 Share Posted May 31, 2009 Not tested. SELECT i.client_name, i.invoice_number, i.complete, COUNT(ip.ref) AS count FROM invoices i INNER JOIN invoices_prod ip ON i.invoice_number = ip.ref GROUP BY i.invoice_number Link to comment https://forums.phpfreaks.com/topic/160393-solved-self-join-and-count/#findComment-846401 Share on other sites More sharing options...
M.O.S. Studios Posted May 31, 2009 Author Share Posted May 31, 2009 thats awesome, thanks worked liek a charm Link to comment https://forums.phpfreaks.com/topic/160393-solved-self-join-and-count/#findComment-846403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.