Answer the question
In order to leave comments, you need to log in
WHERE clause not working with subquery?
Here is the query code
$query = " SELECT article.*,
(SELECT COUNT(*) FROM comments WHERE comments.note_id = article.title_url AND comments.lang = '$lang') AS comments_count
FROM $table AS article";
I need to make a WHERE query after the $table variable $table.lang = '$lang'
Answer the question
In order to leave comments, you need to log in
1) Passing anything to a request without escaping is considered unsafe.
2) in your case, you write as article, it is obvious that you need to use it in where
$query = " SELECT article.*,
(SELECT COUNT(*) FROM comments WHERE comments.note_id = article.title_url AND comments.lang = '$lang') AS comments_count
FROM $table AS article
WHERE article.lang = '$lang'";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question