単一のMySQLクエリでこのようなことを行うにはどうすればよいですか?
select `value_a`
from `table_1`
where `value_b` = (select `value_b` from `table_2` where `value_c` = `x`);
私はCodeIgniterを使用しているので、ActiveRecordsを使用できます。
単一のMySQLクエリでこのようなことを行うにはどうすればよいですか?
select `value_a`
from `table_1`
where `value_b` = (select `value_b` from `table_2` where `value_c` = `x`);
私はCodeIgniterを使用しているので、ActiveRecordsを使用できます。
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);