my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes MySQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 32481
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySQL query
 
It's not a secret anymore!