Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all!

I have a problem about querying in MySQL. I am developing a desktop application particularly an Inventory System. I have tables Products, ProductCategory, ReceiveItems. My problem is on how to display results in my reports based on the ProductCategory from Products and ReceiveItems which results only into at least three (3) items per ProductCategory.

Is there any MySQL function using Limit based on Group By result?

Thank you....
Posted
Comments
_Asif_ 20-Aug-13 1:15am    
What have you tried ?
Sriram Bala 20-Aug-13 2:10am    
Hello Romeland,
You need to mention the table columns and the constraints defined to relate the tables. This will provide us an idea to help you writing a query to suffise your requirement, otherwise we are helpless.
Thanks
Sriram.B
BulletVictim 20-Aug-13 4:39am    
Ok I understand what you would like to do,(well somewhat) what exactly is the problem? Are you only receiving three results or do you only want three results per ProductCategory to be returned and you are not sure how to do this?
Romeland C. dela Peña 21-Aug-13 20:31pm    
You got it Sriram..

i only want to display three latest results per ProductCategory to be returned.

i made this query..

SELECT tblp.ProductCode, tblp.Description, tblp.ProductCategory, count(*) as TotalRecordEachProduct
FROM (((tblproductlist tblp
INNER JOIN tblproductcategory tblpc
ON tblp.ProductCategory = tblpc.ProductCategory)
INNER JOIN tblreceivedetails tblrd
ON tblp.ProductCode = tblrd.ProductCode)
INNER JOIN tblreceive tblr
ON tblrd.TransNo = tblr.TransNo)
GROUP BY tblp.ProductCategory, tblrd.Description;
BulletVictim 22-Aug-13 5:48am    
Ok Have a look at this site. This might be exactly what you are looking for.
http://www.sqlservercurry.com/2009/02/retrieve-last-n-rows-based-on-condition.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900