Good day! There is not much experience with sql, but I know the basics. Practice has shown that the fundamentals are not enough and I cannot find a solution (maybe I was looking badly, maybe there are not enough convolutions ...). The essence of the question is the following: there is the formation of the sql query:
$sql = "select usr.id, usr.$this->attributeNameUser as $this->attributeNameUser, msg.cnt as cnt_mess "; $sql .= "from $this->userTableName as usr "; $sql .= "inner join "; $sql .= "(select from_id, count(id) as cnt from $table_name where status = 1 and whom_id = :user_id GROUP by from_id) as msg "; $sql .= "ON msg.from_id = usr.id "; $sql .= " where usr.id != :user_id "; Two tables are used here: user and message. This query returns the number of new messages from users (status = 1). If you remove this condition - it will return all the messages to me as new ... Question: Is it possible to correct the request that he would take users with whom I have a correspondence, and in the cnt property I entered values with status 1 ??