Hi guys,

I need to order a result set based on a count, which is working fine, but there may be times when an override comes in to effect and I need to get that to take precedence. I'm not entirely sure how to go about it though. I thought I'd got it, but then I realised that it was actually sorting by no order at all, unless the override value was set, at which point it fell in to place where it was supposed to.

Basically it works like this:
Code MySQL:
SET @i = 0;
SELECT t1.id
	 , t1.name
	 , IF (t2.pos, t2.pos, @i:=@i+1) pos
	 , count(*) counter
  FROM t1
 LEFT
  JOIN t2
	ON t1.id = t2.id
GROUP BY
	t1.groupid
ORDER BY
	pos ASC,
	counter DESC
LIMIT 10;
I think that's right. What's basically happening is that the override value is positioning the row where it's supposed to in the resultset, but the rest of the data is out of order. Help!