Fadion Posted September 27, 2007 Share Posted September 27, 2007 I am working on a lyrics website and im making a query to show the top 20 artists based on the sum of views on their songs. I have this query which is working on local, but online im having problems. It is a shared host with php 4.3.11 and mysql 5. The error is "invalid use of group function". Im not very good with queries, other then simple selects, updates etc. If anyone can give any advice to make this query work. Thank you. SELECT artist, SUM(views) FROM texts GROUP BY artist ORDER BY SUM(views) DESC LIMIT 20 Quote Link to comment https://forums.phpfreaks.com/topic/70967-solved-query-problem/ Share on other sites More sharing options...
Barand Posted September 27, 2007 Share Posted September 27, 2007 Dp you need SUM or just COUNT? Anyway, try SELECT artist, SUM(views) as totviews FROM texts GROUP BY artist ORDER BY totviews DESC LIMIT 20 Quote Link to comment https://forums.phpfreaks.com/topic/70967-solved-query-problem/#findComment-356814 Share on other sites More sharing options...
Fadion Posted September 27, 2007 Author Share Posted September 27, 2007 While testing i realised "ORDER BY SUM(views)" was giving me the problem, but didnt think of passing that variable with AS. Thanks a lot, it worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/70967-solved-query-problem/#findComment-356855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.