WikiFatalError

Error performing query:
	SELECT l.from as pid, w.pagename
	FROM links as l, wiki as w
	WHERE l.to =  AND l.dist = 1 AND w.pid = l.from AND ( l.rel = 'up'  OR l.rel = 'p')
	GROUP BY pid
	ORDER BY w.pagename
	

MySQL error: 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 'AND l.dist = 1 AND w.pid = l.from AND ( l.rel = 'up' OR l.rel = 'p') GROUP BY ' at line 3