0

単一のMySQLクエリでこのようなことを行うにはどうすればよいですか?

select `value_a` 
from `table_1` 
where `value_b` = (select `value_b` from `table_2` where `value_c` = `x`);

私はCodeIgniterを使用しているので、ActiveRecordsを使用できます。

4

1 に答える 1

5

JOINこれには、を使用することもできます。

select t1.value_a
from table_1 t1
inner join table_2 t2
  on t1.value_b = t2.value_b
where t2.value_c = 'x'

既存のクエリを使用することもできますが、xは一重引用符ではなくバッククォートで囲まれています。

select `value_a` 
from `table_1` 
where `value_b` = (select `value_b` from `table_2` where `value_c` = 'x);
于 2013-01-17T23:19:14.693 に答える