Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hideously over complicated way to do it in a single sql statement for 3 fixed columns, coping with up to 1000 drinks in each category.</p> <pre><code>SELECT DrinkCategory1Subselect.drink_name AS 'Drink Category Title', DrinkCategory2Subselect.drink_name AS 'Drink Category Title 2', DrinkCategory3Subselect.drink_name AS 'Drink Category Title 3' FROM (SELECT a.i+b.i*10+c.1*100 AS aCounter FROM (SELECT 0 AS i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) a, (SELECT 0 AS i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) b, (SELECT 0 AS i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) c) Deriv1 INNER JOIN (SELECT c.drink_name, @Counter := @Counter + 1 AS aCounter FROM drinks_category a INNER JOIN drinks_lookup b ON a.drink_category_id = b.drink_category_id INNER JOIN drinks c ON b.drink_id = c.drink_id CROSS JOIN (SELECT @Counter:=0) NothingUseful WHERE a.drink_category_id = 1 ORDER BY c.drink_id) DrinkCategory1Subselect ON DrinkCategory1Subselect.aCounter = Deriv1.aCounter INNER JOIN (SELECT c.drink_name, @Counter := @Counter + 1 AS aCounter FROM drinks_category a INNER JOIN drinks_lookup b ON a.drink_category_id = b.drink_category_id INNER JOIN drinks c ON b.drink_id = c.drink_id CROSS JOIN (SELECT @Counter:=0) NothingUseful WHERE a.drink_category_id = 2 ORDER BY c.drink_id) DrinkCategory2Subselect ON DrinkCategory2Subselect.aCounter = Deriv1.aCounter INNER JOIN (SELECT c.drink_name, @Counter := @Counter + 1 AS aCounter FROM drinks_category a INNER JOIN drinks_lookup b ON a.drink_category_id = b.drink_category_id INNER JOIN drinks c ON b.drink_id = c.drink_id CROSS JOIN (SELECT @Counter:=0) NothingUseful WHERE a.drink_category_id = 3 ORDER BY c.drink_id) DrinkCategory3Subselect ON DrinkCategory3Subselect.aCounter = Deriv1.aCounter WHERE DrinkCategory1Subselect.drink_name IS NOT NULL OR DrinkCategory2Subselect.drink_name IS NOT NULL OR DrinkCategory3Subselect.drink_name IS NOT NULL ORDER BY Deriv1.aCounter </code></pre> <p>Not tested. Better to do the formatting in php, but was bored</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload