show the result of matching two tables

G

Guest

I do the matching of two tables, what I'm trying to be solve is how to
display of all the contents of source table even without matching with
another table but calculate the flag into 1 for those unmatch key. look at my
code above

table 1 (source table)
class txtid key flag
2101 10 11111
2102 15 22222
2103 20 33333

table 2 (other table)
key elev
11111 10
55555 20
66666 30

the result I want is
class txtid key flag
2101 10 11111 1
2102 15 22222
2103 20 33333

SELECT table1.TXTID
FROM table1 left JOIN table2 ON table1.KEY = table2.KEY
WHERE (((table2.KEY) Is Null));

In this code, display only the unmatch key.

thanks in advance
 
M

Marshall Barton

jhun said:
I do the matching of two tables, what I'm trying to be solve is how to
display of all the contents of source table even without matching with
another table but calculate the flag into 1 for those unmatch key. look at my
code above

table 1 (source table)
class txtid key flag
2101 10 11111
2102 15 22222
2103 20 33333

table 2 (other table)
key elev
11111 10
55555 20
66666 30

the result I want is
class txtid key flag
2101 10 11111 1
2102 15 22222
2103 20 33333

SELECT table1.TXTID
FROM table1 left JOIN table2 ON table1.KEY = table2.KEY
WHERE (((table2.KEY) Is Null));

In this code, display only the unmatch key.


I think this is what you're looking for:

SELECT table1.Class, table1.TXTID, table1.Key,
IIf(table2.KEY Is Null, Null, 1) As Flag
FROM table1 left JOIN table2 ON table1.KEY = table2.KEY
 
G

Guest

Hi Marsh

Thanks for your time, I followed the code that you gave me but there is an
error "Type mismatch in expression" Here is the code
sourcet = Is my table 1
destt = Is my table 2

SELECT sourcet.CLASS, sourcet.TXTID, sourcet.KEY, IIF(destt.key is null,
null, 1) as flag
FROM sourcet LEFT JOIN destt ON sourcet.KEY = destt.KEY;


Tirso
 
G

Guest

Hi Marsh

I finally found out the error, it has different type. Now it works fine.

Thank you so much.

Good Day
Jhun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top