tags:

views:

38

answers:

3

I get the following error below and was wondering how can I correct this problem?

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 'IF(articles_comments.parent_comment_id = articles_comments.comment_id AND users.' at line 4

Here is my MySQL code.

SELECT * 
FROM users
INNER JOIN articles_comments ON users.user_id = articles_comments.user_id
IF(articles_comments.parent_comment_id = articles_comments.comment_id AND users.active IS NULL AND users.deletion = 0) AS no
AND users.active IS NULL
AND users.deletion = 0
A: 

It's difficult to find out what you are trying to do here, but in order to filter (put a condition) your query, you need a where clause.

Also, your IF statement is misplaced.

Something like this:

SELECT *
  FROM users INNER JOIN articles_comments ON users.user_id = articles_comments.user_id
 WHERE users.active IS NULL
   AND users.deletion = 0
Pablo Santa Cruz
So how would my code look like?
blah
I get this error now `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 ') AS no FROM users INNER JOIN articles_comments ON users.user_id = articles_c' at line 1`
blah
Try it now.....
Pablo Santa Cruz
A: 
SELECT * 
FROM users
INNER JOIN articles_comments ON users.user_id = articles_comments.user_id
WHERE (articles_comments.parent_comment_id = articles_comments.comment_id AND users.active IS NULL AND users.deletion = 0)
AND users.active IS NULL
AND users.deletion = 0
Svisstack
Now I get this 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 'AS no AND users.active IS NULL AND users.deletion = 0 LIMIT 0, 30' at line 1`
blah
because you dont use my query, i make in her some other change not only adding WHERE clause
Svisstack
A: 

That query doesn't make sense at the moment.... I think you have got the WHERE CLAUSE mixed up with the IF clause.

Your question is a little vague too, it is hard to understand what you are trying to do.

Your Select * From, JOIN part is ok.

You need to use the WHERE clause instead tho.

i.e.

SELECT * FROM USERS
INNER JOIN articles_comments ON users.user_id = articles_comments.user_id 
AND articles_comments.parent_comment_id = articles_comments.comment_id 
WHERE users.active IS NULL 
AND users.deletion = 0

You don't seem to be selecting anything fomr the articles_comments table though? A more thorough explantion of the problem will help.

Wes Price