The verb 'work' takes the prepositions 'at' and 'in'.
1. This is the factory where they want to work.
at: This is the factory they want to
work at.
in: This is the factory they want to
work in.
The prepositions 'at' and 'in' coupled with the noun they modify (i.e., factory) refer to a location:
Where do they want to work?
They want to work
in this factory.
They want to work
at this factory.
When prepositional phrases, like 'at this factory' and 'in this factory', refer to a location, they function as adverbs; they answer the question, Where?, and that's why 'where' works here as a relative adverb:
This is the factory
where they want to work.
This is the factory
at which they work.
This is the factory
in which they work.
As for our second example sentence, below, the verb 'visit' doesn't require a prepositional phrase. These phrases are ungrammatical: *visit to + <location>, *visit at + <location>, so 'where' isn't needed here:
2. *This is the factory
where they want to visit.
at: *This is the factory they want to
visit at. <ungrammatical>
in: *This is the factory they want to
visit in. <ungrammatical>
The verb 'visit' doesn't take 'at' or 'in', or even 'to', but the verb 'go' does:
They want to go
to the factory.
This is
the factory they want to go
to.
This is
the factory where they want to go.
Hope that helps.
