trying to get rows that have a certain field value to show first in the results. I think I have it right but it doesn't seem to work:
SELECT * FROM
(
SELECT a.article_id, a.`category_name`, a.`category_id`,
@rank1 := IF( @val = a.article_id, @rank1 +1, 1 ) AS rank1,
@val := a.article_id
FROM
(
SELECT r.article_id, c.`category_name`, c.`category_id`
FROM `article_category_reference` r
INNER JOIN `articles_categorys` c ON c.category_id = r.category_id
WHERE r.article_id IN (?,?,?,?)
ORDER BY r.`article_id`, CASE WHEN (c.`show_first` = 1) THEN 0 ELSE 1 END ASC, c.category_name ASC
) AS a
)as Z
WHERE Z.rank1 < 5
Explanation: This is to get a list of tags for all articles on the current page of a blog, and limit each to 4.
I thought checking "show_first" = 1 would work but it seems to do nothing in this case.
mysql Ver 15.1 Distrib 10.4.11-MariaDB