MySQL Forums
Forum List  »  Newbie

Re: Select Statement
Posted by: Phillip Ward
Date: April 13, 2021 04:08AM

Quote

I have a select statement similar to the following:
select * from Column_A where ID = '01'

You don't select from Columns.
You select [one or more Columns] from Tables.

select ID 
from Table_A
where ID = '01' ;

You can run your query as a subquery:

select ID
from Table_B 
where ID in 
(
  select ID 
  from Table_A 
  where ID = '01'
) ;

Or, if you're feeling a little more adventurous, you can do it with a Join:

select b.ID 
from Table_B b
inner join Table_A a 
      on   b.ID = a.ID 
where a.ID = '01'

A couple of other things:

- Don't use "select *" in application code.
- If Table_A.ID and Table_B.ID are actually numbers, then hold them in a numeric Data Type, say int. Chopping and changing between Data Types in your queries only serves to slow them down.

Options: ReplyQuote


Subject
Written By
Posted
April 13, 2021 02:20AM
Re: Select Statement
April 13, 2021 04:08AM
April 13, 2021 08:34AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.