此查詢工作正常:添加數從另一個表中現有的查詢
SELECT posts.titulo as value,
posts.id as id,
posts.img_src as img,
posts.id_familia,
posts.tiempo,
posts.votos,
familias.clave,
familias.id as fm,
textos.clave,
textos.texto as familia,
FROM posts,familias,textos
WHERE posts.id_familia = familias.id AND familias.clave = textos.clave AND textos.lengua = ".detectarIdioma()."
and posts.id_usuario = $term
ORDER BY posts.id DESC
但現在我想補充了多少評論後,至極處於住客評論表
SELECT posts.titulo as value,
posts.id as id,
posts.img_src as img,
posts.id_familia,
posts.tiempo,
posts.votos,
familias.clave,
familias.id as fm,
textos.clave,
textos.texto as familia,
count(comentarios.id)
FROM posts,familias,textos
JOIN comentarios ON comentarios.id_post = posts.id
WHERE posts.id_familia = familias.id AND familias.clave = textos.clave AND textos.lengua = ".detectarIdioma()."
and posts.id_usuario = $term
ORDER BY posts.id DESC
的一點是,MySQL錯誤是
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 '*) FROM posts,familias,textos JOIN comentarios ON ' at line 12
任何想法我在這裏錯過了什麼?
嗨,那裏,謝謝你的時間。像這個查詢現在工作,問題是我沒有想到這一點,只是回覆評論的帖子,我想評論不要過濾查詢,只是添加每個帖子的評論數,是那麼棘手? –
我更新了sql(你可能需要也可能不需要「group by」 - 不知道關於mysql) – Gerrat