Link to home
Start Free TrialLog in
Avatar of rafaelrgl
rafaelrgl

asked on

how to select rows from other table to compare

hi, i have 2 tables:

table1                                                         table2
id       number1      number2                           id               number1

1            10               7                                     1                    8
2             5                 3                                     2                   10
3              8                 3


i want create an select that makes the test to see if the table2 has the record number1 for table1. so we will create an table like this:

table3                                                        
id       number1      number2     haveregistry                        

1            10               7               true  
2             5                 3              false                      
3              8                 3              true


any idea?

ASKER CERTIFIED SOLUTION
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ephraim Wangoya
try
SELECT tabl1.id, table1.number1, table1.number2, 
	case 
		when table2.number1 IS null then 
			'false' 
		else 
			'true' 
	end [haveregistry]
from tabe1 
left join table2 on table1.id = table2.id

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial