Re: query problem

Posted: 07-11-2003, 09:17 AM
SELECT top5.PRODID, p.PRODNAME
FROM (
SELECT TOP 5 SALES = COUNT(*), PRODID
FROM SALES
GROUP BY PRODID
ORDER BY SALES DESC ) AS top5
INNER JOIN PRODUCTS p ON p.PRODID = top5.PRODID

ORDER BY top5.SALES DESC

--
Tony Rogerson
SQL Server MVP
http://www.sqlserverfaq.com?mbr=21
(Create your own groups, Forum, FAQ's and a ton more)


Reply With Quote

Responses to "Re: query problem"

Jacco Schalkwijk
Guest
Posts: n/a
 
Re: query problem
Posted: 07-11-2003, 09:21 AM
SELECT TOP 5 P.PRODNAME, COUNT(*) AS total_sales
FROM PRODUCTS P
INNER JOIN SALES s
ON P.PRODID = s.PRODID
GROUP BY P.PRODNAME
ORDER BY total_sales DESC

--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.


"He Sha" <hesha@hotmail.com> wrote in message
news:eE5k3w4RDHA.3700@tk2msftngp13.phx.gbl...
> Hi all,
>
> There is a table called SALES with a single field called PRODID. An entry
is
> made into this everytime there is a sale.
>
> Doing a SELECT TOP 5 COUNT(*) C, PRODID FROM SALES GROUP BY PRODID ORDER
BY
> C DESC gives me the list of top 5 selling products.
>
> In another table PRODUCTS, there are two fields PRODID, PRODNAME. Is there
a
> way to find out the names of top 5 selling products using a single query?
>
> Thanks,
> HS.
>
>
>

Reply With Quote
He Sha
Guest
Posts: n/a
 
query problem
Posted: 07-11-2003, 09:36 AM
Hi all,

There is a table called SALES with a single field called PRODID. An entry is
made into this everytime there is a sale.

Doing a SELECT TOP 5 COUNT(*) C, PRODID FROM SALES GROUP BY PRODID ORDER BY
C DESC gives me the list of top 5 selling products.

In another table PRODUCTS, there are two fields PRODID, PRODNAME. Is there a
way to find out the names of top 5 selling products using a single query?

Thanks,
HS.



Reply With Quote
Poppy
Guest
Posts: n/a
 
Query Problem
Posted: 02-20-2004, 10:53 AM
I have 2 tables, each which contain usernames and id's.

I need to extract all users from tableA which do not appear in tableB but
cant figure out the syntax of the query.

Any Ideas ?

Thanks in advance


Reply With Quote
Chris Hohmann
Guest
Posts: n/a
 
Re: Query Problem
Posted: 02-20-2004, 06:30 PM
"Poppy" <paul.diamond@NOSPAMthemedialounge.com> wrote in message
news:OJTpog69DHA.4020@TK2MSFTNGP09.phx.gbl...
> I have 2 tables, each which contain usernames and id's.
>
> I need to extract all users from tableA which do not appear in tableB
but
> cant figure out the syntax of the query.
>
> Any Ideas ?
Database? Version? DDL? Sample Data?

Here's a pseudo query since I have no idea what your database looks
like:

SELECT
A.username,
A.id
FROM
tableA AS A LEFT JOIN
tableB AS B ON
A.username = B.username AND
A.id = B.id
WHERE
B.id IS NULL

HTH
-Chris Hohmann



Reply With Quote
Bullschmidt
Guest
Posts: n/a
 
Re: Query Problem
Posted: 02-23-2004, 08:18 AM
And you can use Not In within a query:

http://dbforums.com/showthread.php?p...009post3050009

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply With Quote
tejun
Guest
Posts: n/a
 
Re: query problem
Posted: 02-16-2005, 07:31 PM
When you use Order_By, you must include all fields from your query. You can use the MS Access Upsize tool OR use SQL Server Enterprise Manager Database Tranformation Services (DTS).

-- lnh
Reply With Quote
newuser111
Guest
Posts: n/a
 
Re: query problem
Posted: 02-21-2005, 09:36 PM
thx for your answer.

Do you know where i can get basic info on how to migrate from access to sql
server?
do i need to change the code of the queries contained in my cfm and cfc files?
what are these changes ???



Reply With Quote
Steve Grosz
Guest
Posts: n/a
 
Query problem
Posted: 04-23-2005, 04:41 PM
I have 2 seperate queries:

1)
select *
from vendor
left outer join model
on vendor.PID=model.VendorID
left outer join specs
on model.Model=specs.ProdModel
where vendor.Vendor='#URL.Vendor#'
order by Model

2)
SELECT specs.SpecID
from vendor
left outer join model
on vendor.PID=model.VendorID
left outer join specs
on model.Model=specs.ProdModel
where vendor.Vendor='TGB'

So, why am I getting a error saying that a 'element SPECID is undefined in
specs' when it works with query #2 when I put:

select *, specs.SpecID
from vendor
left outer join model
on vendor.PID=model.VendorID
left outer join specs
on model.Model=specs.ProdModel
where vendor.Vendor='#URL.Vendor#'
order by Model


Reply With Quote
mpwoodward *TMM*
Guest
Posts: n/a
 
Re: Query problem
Posted: 04-23-2005, 05:34 PM
Steve Grosz wrote:
> So, why am I getting a error saying that a 'element SPECID is undefined in
> specs' when it works with query #2 when I put:
>
> select *, specs.SpecID
> from vendor
> left outer join model
> on vendor.PID=model.VendorID
> left outer join specs
> on model.Model=specs.ProdModel
> where vendor.Vendor='#URL.Vendor#'
> order by Model
Just a quick guess, but have you tried specifying the tables in your *
select? e.g. select vendor.*, specs.SpecID from vendor ... I'd give
that a shot first and see if that makes any difference.

Matt

--
Matt Woodward
Team Macromedia - ColdFusion
Reply With Quote
 
LinkBack Thread Tools Search this Thread Display Modes
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Query Error BigNicko7 Coldfusion Database Access 6 05-06-2005 07:40 PM
Query returns no rows... chrson Coldfusion Database Access 4 04-05-2005 04:32 PM
Query of Queries? artists_envy Coldfusion Database Access 3 02-25-2005 03:31 PM
Query problem part 2 tejun Coldfusion Database Access 1 02-21-2005 09:40 PM
Need SQL Query Help from Gurus ctrl+alt+delete Coldfusion Database Access 4 02-18-2005 08:20 PM