msg_info表里面有 id name type body time 字段
msg_read 表里有 msg_id(msg_info表的外键) uid(user表的外键) status(是否状态)
我想在插入 msg_info表 数据的时候 同时查出 type字段符合的用户 并且批量的插入到 msg_read 表中 
请问有什么好办法么?
insert into msg_read(msg_id,uid,status) values (select id from msg_info where cretatetime='2009-06-17 12:00:27' as msgid,select id from sys_users where rightes='12','1')
这么写 也不好用啊 请大家帮帮忙啊!

解决方案 »

  1.   

    你的msg_info表与user表有什么关联的吗?
      

  2.   

    我想在插入 msg_info表 数据的时候 同时查出 type字段符合的用户 并且批量的插入到 msg_read 表中 
    请问有什么好办法么?---------------------------
    你这个也可以考虑用触发器来处理
      

  3.   

    info表里的 type字段 应该是user表里 rightes字段中的一个 应该是用in 查询的吧
    恩 具体数字是 type 应该 是 1  rightes应该是 1,2,3
      

  4.   

    贴记录及要求结果出来看看,考虑用TRIGGER解决
      

  5.   

    对哈触发器 我去查查资料 4楼的TRIGGER我也去看看 谢谢
      

  6.   

    简单trigger
    create table tb1(
        ->  gid int auto_increment primary key,
        ->  color int,
        ->  size int
        -> );
    Query OK, 0 rows affected (0.16 sec)mysql>
    mysql> create table tb2(
        ->  id int auto_increment primary key,
        ->  gid int,
        ->  weight int
        -> );
    Query OK, 0 rows affected (0.05 sec)mysql>
    mysql> create table tb3(
        ->  id int auto_increment primary key,
        ->  gid int,
        ->  c3 int
        -> );
    Query OK, 0 rows affected (0.08 sec)mysql> delimiter |
    mysql>
    mysql> CREATE TRIGGER t_tb1_ai AFTER INSERT ON tb1
        ->   FOR EACH ROW BEGIN
        ->          insert into tb2(gid) values (new.gid);
        ->          insert into tb3(gid) values (new.gid);
        ->   END;
        -> |
    Query OK, 0 rows affected (0.11 sec)mysql>
    mysql> delimiter ;
    mysql>
    mysql> insert into tb1 (color) values (123);
    Query OK, 1 row affected (0.27 sec)mysql> select * from tb1;
    +-----+-------+------+
    | gid | color | size |
    +-----+-------+------+
    |   1 |   123 | NULL |
    +-----+-------+------+
    1 row in set (0.00 sec)mysql> select * from tb2;
    +----+------+--------+
    | id | gid  | weight |
    +----+------+--------+
    |  1 |    1 |   NULL |
    +----+------+--------+
    1 row in set (0.00 sec)mysql> select * from tb3;
    +----+------+------+
    | id | gid  | c3   |
    +----+------+------+
    |  1 |    1 | NULL |
    +----+------+------+
    1 row in set (0.00 sec)
      

  7.   

    用触发器就可以了。参考一下MYSQL帮助手册中的例子。CREATE TABLE test1(a1 INT);
    CREATE TABLE test2(a2 INT);
    CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
    CREATE TABLE test4(
      a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
      b4 INT DEFAULT 0
    );delimiter |CREATE TRIGGER testref BEFORE INSERT ON test1
      FOR EACH ROW BEGIN
        INSERT INTO test2 SET a2 = NEW.a1;
        DELETE FROM test3 WHERE a3 = NEW.a1;  
        UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
      END;
    |delimiter ;INSERT INTO test3 (a3) VALUES 
      (NULL), (NULL), (NULL), (NULL), (NULL), 
      (NULL), (NULL), (NULL), (NULL), (NULL);INSERT INTO test4 (a4) VALUES 
      (0), (0), (0), (0), (0), (0), (0), (0), (0), (0);