user4593252
user4593252

Reputation: 3506

Two related queries needs to be one

I know this is a basic thing but SQL is a serious weak point of mine...

I have the following query ("query1")

select 
    SC.statues, SC_some_real_code 
from 
    [corpdb_gs].[dbo].[Simple_Codes] SC
inner join
    [corpdb_gs].[dbo].[real_simple_essentials] RSE
on 
    SC.statues = RSE.se_statutes 
AND 
    SC.some_real_code = RSE.se_statutes_reason  

I need to return only the rows in table [db2].[dbo].[statusYo] where

    statusYo.code = "query1".SC.statues 
AND 
    statusYo.reason = "query1".SC.some_real_code

Help?

Upvotes: 0

Views: 30

Answers (1)

Manish Shukla
Manish Shukla

Reputation: 59

    select * from [db2].[dbo].[statusYo] query2
    inner join 
   (select 
        SC.statues as statues , SC.some_real_code as some_real_code   
    from 
        [corpdb_gs].[dbo].[Simple_Codes] SC
    inner join
        [corpdb_gs].[dbo].[real_simple_essentials] RSE
    on 
        SC.statues = RSE.se_statutes 
    AND 
        SC.some_real_code = RSE.se_statutes_reason) query1  
on query1.statues =query2.code 
and query1.some_real_code=query2.reason 

this will work for you......

Upvotes: 1

Related Questions