I have this query so far:
SELECT `p`.`id`, cp.pattern_category_id, `p`.`title`, `p`.`filename`, p.precedence
FROM (`patterns` p) JOIN `categories_to_patterns` cp ON `p`.`id` = `cp`.`pattern_id`
JOIN `pattern_categories` pc ON `cp`.`pattern_category_id` = `pc`.`id`
WHERE `cp`.`pattern_category_id` = '29'
Which returns this:
id | pattern_category_id | title | filename | precedence
6 29 Alan alan.jpg 2
7 29 Joe joe.jpg 1
What I want to do is get the row that has the lowest precedence. I’m not sure if i should be using a subquery, doing a min(p.precedence) with some group by’s, or using group by/having.
Any help appreciated.
You could always
ORDER BY p.precedence ASC limit 1does that work for you?