Select entries that are present in other table

ennrike

Registered User.
Local time
Yesterday, 18:47
Joined
Dec 3, 2010
Messages
25
Hi,

I have two tables, TABLE1 that has a column "ORDER_NUMBER" (the primary key) and I have a second table TABLE2 that has also the column "ORDER_NUMBER" these two tables have relationship between using these two columns.

However, I have "ORDER_NUMBER" entries in TABLE2 that has a special column called "OVER_TIME" that is an integer for hours.

How can I select * the entries present in TABLE1 of time "ORDER_NUMBER" that are in TABLE2 and have the OVER_TIME > 5 hours.

Thanks,
 
You can try this:
Code:
select TABLE1.* from TABLE1 inner join TABLE2 
on TABLE1.ORDER_NUMBER = TABLE2.ORDER_NUMBER where TABLE2.OVER_TIME > 5
or
Code:
select TABLE1.* from TABLE1 where TABLE1.ORDER_NUMBER in 
(select TABLE2.ORDER_NUMBER from TABLE2 where TABLE2.OVER_TIME>5)
Both should work. The first one is faster.

Enjoy!
 

Users who are viewing this thread

Back
Top Bottom