Quantcast

SQLServer Select Blah question

pnj

Turbo Monkey till the fat lady sings
Aug 14, 2002
4,696
40
seattle
We are using that Pubs DB if anyone is familiar with that..

I have two tables I getting data from. They are Titles and Sales.

I need to grab the top ten selling titles.


select titles.title, sales.qty from titles,sales where
sales.qty=(Select min(qty)from sales) and titles.title_id=sales.title_id

this grabs the book that has sold the least amount of books. I am not sure how to write a statement that says, "give me the top ten sales". I can get the max but that doesn't help either.

What is the damm syntax I am looking for..?!!?:bonk:
 

BadDNA

hophead
Mar 31, 2006
4,263
237
Living the dream.
This should get you going:

SELECT * FROM competition WHERE id NOT IN (SELECT id FROM competition ORDER BY score DESC LIMIT 19) ORDER BY score DESC LIMIT 10

or

SELECT * FROM competition ORDER BY score DESC LIMIT 19,10;

or

SELECT TOP (10) ShippingId
FROM Shipping
WHERE (ShippingId NOT IN
(SELECT TOP (20) ShippingId
FROM Shipping AS Shipping_1
ORDER BY ShippingId DESC))
ORDER BY ShippingId DESC
 

binary visions

The voice of reason
Jun 13, 2002
22,162
1,261
NC
You post in the Lounge for "visibility" but having sixteen thousand uninterested and unhelpful viewings isn't as useful as having two good ones :p

I've never seen a single tech post get answered in the Lounge that would have gone unanswered in here because it didn't get enough views :bonk:
 

pnj

Turbo Monkey till the fat lady sings
Aug 14, 2002
4,696
40
seattle
Google didn't help. well, it got me sorta going but I couldn't find exactly what I needed to get it to work.

BadDNA-when you're using LIMIT 19,10 what is the 19 doing?

I'll try this code when I get back to school tomorrow. I know I had TOP in my code at one point in time but couldn't get it to work...

VB - thanks brotha:)