How can I do something like this in a Single MySQL Query?
select `value_a`
from `table_1`
where `value_b` = (select `value_b` from `table_2` where `value_c` = `x`);
I use CodeIgniter so I can use Active Records.
How can I do something like this in a Single MySQL Query?
select `value_a`
from `table_1`
where `value_b` = (select `value_b` from `table_2` where `value_c` = `x`);
I use CodeIgniter so I can use Active Records.
You can also use a JOIN
for this:
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'
You can also use your existing query, but the x
is surrounded by backticks and not single quotes:
select `value_a`
from `table_1`
where `value_b` = (select `value_b` from `table_2` where `value_c` = 'x);