It's not clear what you're trying to accomplish. Some sample data and sample expected results would help to clear that up. If the mainzip and alternatezip both match rows in the zipcode table are you saying you just want the row that matches the mainzip returned, otherwise return whichever row matches?