sql select statement

table a has a column a_id;
table b has a column b_id;
I need select the rows where the a_id=b_id;

select * from a where a.a_id=b.b_id
Who is Participating?
SharathData EngineerCommented:
Where is table b in your query? Any of these will work.
select * from a where a_id in (select b_id from b)

Open in new window

select a.* from a inner join b on a.a_id = b.b_id

Open in new window

select * from a where exists (select 1 from b where a_id = b_id)

Open in new window

Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
that should work fine
That'll work if you want to go through table b row-by-row.  What you may want to do instead is use some type of JOIN statement.  Since you tagged MySQL as the database type, check the My SQL Reference Manual for more information on how to do that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.