mysql在一个命令中选择id和count?

时间:2012-07-14 22:03:00

标签: mysql

使用Mysql如何将这两个命令合并为一个?

select id from User where name='name'
select count(*) from Msg where user_id=@id

1 个答案:

答案 0 :(得分:3)

您可以加入表格:

SELECT COUNT(*)
FROM User a
INNER JOIN Msg b ON a.id = b.user_id
WHERE a.name = 'name'