Hello.
No, it isn't. Here is the test case:
create table comments(id int auto_increment,newsid int,primary key(id));
create table news(id int,comments int);
insert into news(id) values('1'),(2),(3),(4),(5);
insert into comments(newsid) values(1),(1),(2),(4),(4),(4);
update news set comments = (select count(id) from comments where
newsid = news.id group by newsid);
mysql> select * from news;
+------+----------+
| id | comments |
+------+----------+
| 1 | 2 |
| 2 | 1 |
| 3 | NULL |
| 4 | 3 |
| 5 | NULL |
+------+----------+
See:
http://dev.mysql.com/doc/mysql/en/correlated-subqueries.html
Enrique Sanchez Vela <[EMAIL PROTECTED]> wrote:
>
>
>
>
> --- Gleb Paharenko <[EMAIL PROTECTED]> wrote:
>
>> Hello.
>>
>> What about this:
>>
>> UPDATE news
>> SET comments =
>> (
>> SELECT COUNT(id)
>> FROM comments
>> WHERE newsid = news.id
>> GROUP BY newsid
>> );
>>
>>
>
> Isn't the previous query going to update the
> news.comments with the last count from the sub-query?
>
>
--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Gleb Paharenko
/ /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED]
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.NET
<___/ www.mysql.com
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]