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
right?
keepworkingAsked:
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

0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
that should work fine
0
 
G_Hosa_PhatCommented:
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.
0
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.