Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join

Status
Not open for further replies.

ronwmon

Programmer
Joined
Jul 13, 2007
Messages
97
Location
US
I need to do a join on two fields. I have a table that has fields titled agency_no and permit_no. I have another table with a list of agency's and permits I want to keep. I need to delete records in another table where the combination of the agency_no and permit_no do not exist.

I have accomplished this task on other tables referring to only one field with the following code:

delete from contact_link
from dbo.contact_link
left join User_ID_Save on dbo.contact_link.contact_no = User_ID_Save.contact_no
where User_ID_Save.contact_no is null

Thanks for any assistance you can provide.

Ron--
 
Just add the 2nd condition. Like this...

Code:
delete contact_link
from   dbo.contact_link
       left join User_ID_Save 
         on dbo.contact_link.contact_no = User_ID_Save.contact_no
         [!]and dbo.contact_link.OtherField = User_ID_Save.OtherField[/!]
where  User_ID_Save.contact_no is null

-George

"the screen with the little boxes in the window." - Moron
 
Y'know I'm sure I've seen that left join plus null idiom somewhere before - and recently too. Give me a minute, I'm sure it'll come to me...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top