Nu tad tad, kad pieglabā refereri novāc "browsera šitus" vai arī
http://dev.mysql.com/doc/refman/5.0/en/string-functions.htm
SELECT ... LEFT(RIGHT(referer, LOCATE('q=', referer)), LOCATE('&', LOCATE('q=', referer))); as q ...
nez vai strādā un baigi samuģīti