Welcome to Geeklog, Anonymous Wednesday, November 27 2024 @ 12:53 am EST
Geeklog Forums
Whats wrong with this SQL?
Anonymous
Anonymous
Can anybody tell me why this SQL produces this "1064: You have an error in your SQL syntax near '' at line 1"
SELECT DISTINCT count(*) AS dups,type,question,gl_stories.title,gl_stories.sid,qid FROM gl_comments LEFT JOIN gl_stories ON ((gl_stories.sid = gl_comments.sid) AND ((gl_stories.perm_anon >= 2))) LEFT JOIN gl_pollquestions ON ((qid = gl_comments.sid) AND ((gl_pollquestions.perm_anon >= 2))) WHERE (gl_comments.date >= (NOW() - INTERVAL 172800 SECOND)) AND ((((gl_stories.perm_anon IS NOT NULL)) OR ((gl_pollquestions.perm_anon IS NOT NULL))) OR (gl_comments.type='filemgmt')) GROUP BY gl_comments.sid ORDER BY gl_comments.date DESC LIMIT 15But, if I run the SQL directly in mysql, it produces this result:
SELECT DISTINCT count(*) AS dups,type,question,gl_stories.title,gl_stories.sid,qid FROM gl_comments LEFT JOIN gl_stories ON ((gl_stories.sid = gl_comments.sid) AND ((gl_stories.perm_anon >= 2))) LEFT JOIN gl_pollquestions ON ((qid = gl_comments.sid) AND ((gl_pollquestions.perm_anon >= 2))) WHERE (gl_comments.date >= (NOW() - INTERVAL 172800 SECOND)) AND ((((gl_stories.perm_anon IS NOT NULL)) OR ((gl_pollquestions.perm_anon IS NOT NULL))) OR (gl_comments.type='filemgmt')) GROUP BY gl_comments.sid ORDER BY gl_comments.date DESC LIMIT 15But, if I run the SQL directly in mysql, it produces this result:
+------+----------+----------+-------+------+------+ | dups | type | question | title | sid | qid | +------+----------+----------+-------+------+------+ | 2 | filemgmt | NULL | NULL | NULL | NULL | +------+----------+----------+-------+------+------+ 1 row in set (0.01 sec) [/code] Now, if I remove the "OR (gl_comments.type='filemgmt'), the SQL works without a problem.
I'm tearing my hair out with this
...deon
5
5
Quote
Anonymous
Anonymous
The SQL call you posted here runs without syntax errors in phpmyadmin on my system with the gl_comments.type = 'filemgmt' condition. I don't know maybe you're confusing it with your extra parenthesis in the WHERE clause. Or, are you using variables in the statement and replaced them with values here? If so, the problem is the variable you're feeding it.
6
6
Quote
All times are EST. The time is now 12:53 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content