aspose file tools*
The moose likes JDBC and the fly likes MySQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL query" Watch "MySQL query" New topic
Author

MySQL query

basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
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

Joined: May 26, 2003
Posts: 31057
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
jQuery in Action, 2nd edition
 
subject: MySQL query