•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 397,568 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,494 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 52579 | Replies: 8
Hi guys here is my working sql query
Select MAX(Hits)'Hits', SUM(Hits)'Total', UserID
From sf_articles
Group By UserID
My problem is, when I want to select other columns as well as the current ones. It gives me a lovely error:
Server: Msg 8120, Level 16, State 1, Line 1
Column 'sf_articles.ArtID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Basically what I want to do is get those columns, and get the info from the records that contain the maximum hits.
For example. I have two records, one with 2 hits, the other with 5. I want to get all the info from the one with 5 hits. There will be an end result of about 7 records at the end since there are 7 users.
PLEASE HELP! I AM TEARING MY HAIR OUT!
Cheers,
Slade
Select MAX(Hits)'Hits', SUM(Hits)'Total', UserID
From sf_articles
Group By UserID
My problem is, when I want to select other columns as well as the current ones. It gives me a lovely error:
Server: Msg 8120, Level 16, State 1, Line 1
Column 'sf_articles.ArtID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Basically what I want to do is get those columns, and get the info from the records that contain the maximum hits.
For example. I have two records, one with 2 hits, the other with 5. I want to get all the info from the one with 5 hits. There will be an end result of about 7 records at the end since there are 7 users.
PLEASE HELP! I AM TEARING MY HAIR OUT!
Cheers,
Slade
Formerly known as Slade.
•
•
•
•
Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
ad advertising ajax architecture asp backup beta business centro crash daniweb database dell developer development doubleclick enterprise google hacker internet linux longhorn mail microsoft mmorpg msdn news novell office open qmail red hat rhel security server smtp software source sql survey suse vista windows windows server
- Freelance Web designer PHP, MySQL, ASP, SQL Server 2000 (Post your Resume)
- Ms Sql Server 2000 (MS SQL)
Other Threads in the MS SQL Forum
- Previous Thread: ms sql2005:error msg
- Next Thread: Query Help



Threaded Mode