I’m looking for the best way to order a result set based on the ‘most viewed’ count of another table?
I have a products table and a history table. The history table stores the view count of the products and is linked in by the product_id.
What is the best way to order the product listing by the ‘view_count’ column in the history table?
Thanks for help with this.
Assuming there is a one-to-one- relationship between
productsandhistorythe query would be something like:If there are multiple
historyrecords for eachproductthan its a different scenario. This might not scale, you might consider adding theview_counttoproductsand just incrementing it on each view.