This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL query

 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i am having 3 tables named as follows,
products,
company,
productcategory.
i am having a table for storing history os selling.named as
productssoldhistory.
the fields of productssoldhistory table are,
soldhistoryid,
productid,
date,
the fields of products table are,
productid,
productname,
copmanyid,

the fields of company table are,
companyid,
companyname.

i wanna select the companyname of 10 maximum sold products from productssoldhistory table.companyname is in company table.how to use a query for this in mySQL without subqueries?.
thanks
---
basha
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basha,
You can use an aggregate function and order the results. For example,

Then your java code would get the results until the count falls below ten.
Also, note that mysql supports subqueries starting with version 4.1.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic