SQL count(): The Most Popular Cake

So how do yo find the most popular cake in the Shire Bakery? Here’s an idea.

PhpMyAdmin: the most popular caske
PhpMyAdmin: the most popular caske
-- Show the best cookie
-- See: Ben Forta Chap. 16
SELECT COUNT( cakes.cake ) AS 'popular', cakes.cake, costumers.who
FROM cakes, costumers, likes
-- sort out the cardinalities (relations)
WHERE cakes.cakes_id = likes.cakes_id
AND costumers.costumers_id = likes.costumers_id

-- group by the cake 
group by cakes.cake

-- and sort (most popular and downwards)
order by popular desc

Published by

Per Thykjaer Jensen

I am a Senior Lecturer in front- and backend web programming at the Multimedia Design and Communication Programme at Business Academy Aaarhus. I speak several languages: PHP, Python, MySQL, JavaScript, Nodejs, HTML, CSS, and ... Danish. Background: MA it, interaction and multimedia - MA Literature history - BA Art History.

Leave a Reply