I have asked a question before about ordering MYSQL results by alternating (1,2,3 – 1,2,3 – 1,2,3) rows and I have found this answer
I tried to apply the code to my situation and this is what I have got:
SELECT
x.id,
x.pic0,
x.bio,
x.bio2,
x.site,
x.url,
x.applet
FROM
(SELECT
t.id,
t.pic0,
t.bio,
t.bio2,
t.site,
t.url,
t.applet
CASE
WHEN @site != t.site THEN @rownum := 0
WHEN @site = t.site THEN @rownum := @rownum + 1
ELSE @rownum
END AS rank,
@site := t.site
FROM ".$table." t,
(SELECT @rownum := 0, @site ORDER BY t.site) r) x
ORDER BY x.rank, x.site
This is the MYSQL error I am getting – server is using MYSQL 5.1
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN @site != t.site THEN @rownum := 0 WHEN @site = t.site THEN @rownum :' at line 18
-
I am a total newb and this query, I cannot even begin to understand it 🙂 so I don’t have the slightest idea on what is wrong with it.
-
How to add WHERE conditions to this query?
WHERE bio LIKE ‘value’ and so on
you are missing a
,add the
wherehere: