Sorry, for unspecific title.
I’m working with MySQL on PHP.
These are my tables:
+++++++++++++++++++++++
|........thread.......|
+++++++++++++++++++++++
|.id.|..title..|..ok..|
+++++++++++++++++++++++
|.45.|.baslik.|...1...|
|.53.|.baslik.|...0...|
|.56.|.baslik.|...1...|
+++++++++++++++++++++++
+++++++++++++++++++++++++++++++++
|............comment............|
+++++++++++++++++++++++++++++++++
|.id.|..text..|.ok.|.thread_id..|
+++++++++++++++++++++++++++++++++
|.1..|.falan..|.0..|....45......|
|.3..|.filan..|.1..|....56......|
+++++++++++++++++++++++++++++++++
What I need is to get all checked (ok=1) rows of “thread” table with row count providing equality of thread.id = comment.thread_id and comment.ok=1.
When I use the following query, I get all count of comment checked or unchecked.
select thread.*, count( comment.thread_id ) as countComment from `thread` left join `comment` on thread.id=comment.thread_id where thread.ok='1' group by thread.id
Output I want to get must be like following one.
++++++++++++++++++++++++++++++++++++
|.id.|.title..|..ok.|.commentCount.|
++++++++++++++++++++++++++++++++++++
|.45.|.baslik.|...1.|......0.......|
|.56.|.baslik.|...1.|......1.......|
++++++++++++++++++++++++++++++++++++
Thanks,
Try this:
LEFT JOINcommentON thread.id = comment.thread_id AND comment.ok = '1'