Question : Need SQL Script

I have two tables and both have around 20 million records. I want to add flag value as 'Y'  if  table1 GID for the phone is existing in the table2 along with same phone otherwise flag value is 'N'. Then insert this result into Table3.
Join condition is
Table1.PHONE=Table2.PHONE AND TABLE1.GID=TABLE2.GID
Please help me to write the script efficiently(if possible in single query).Thanks in advance

TABLE1
REPORTDATE
GID
PHONE

TABLE2
PHONE
GID

TABLE3   (result)
REPORTDATE
GID
PHONE
FLAG





Answer : Need SQL Script

Assuming Table3 is empty to start this should do it.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
INSERT INTO table3
SELECT Getdate()    AS 'reportdate',
       table1.gid   AS 'gid',
       table1.phone AS 'phone',
       flag = CASE
                WHEN Isnull(table2.phone)
                THEN 'N'
                ELSE 'Y'
              END
  FROM table1
       LEFT OUTER JOIN table2
         ON table1.gid = table2.gid
        AND table1.phone = table2.phone
Random Solutions  
 
programming4us programming4us