0

Myisam (Mysql) で何らかの形式の参照整合性を確保するために、サブクエリを使用して更新と挿入を試みています。たとえば、更新にはこれを使用します:

update tbl_a
set col_a='test'
where ID=22 and '2' IN (SELECT ID FROM tbl_b) and '33' IN (SELECT ID FROM tbl_c)

ただし、挿入の同じ原則は機能しません。次のようなことを試しました:

insert into tbl_a
(
a,
b,
c
)
values
(
  now(),
  select ID from tbl_b where ID=2,
  select ID from tbl_c where ID=23
)

挿入中に (複数の) 条件を指定する方法はありますか?

ありがとうパトリック

4

1 に答える 1

1

次のアプローチを検討してください。

insert into tbl_a (a, b, c)
select now(), b.id, c.id from tbl_b b, tbl_c c where b.id=2 and c.id=23
于 2013-07-12T11:03:46.113 に答える