A model can fire a Pistol even if there are enemy units within 1" of its own unit, but it must target the closest enemy unit.
I have been playing it as the closests, it never came up at my local as most dont shoot pistols anyways at my local, and the few that do are in
CC or about to be in
CC so its normally the closest anyways, but another persona i know did just questioned it. So i wanted to get a feel from Dakka.
Full rule: For quick reference
https://whc-cdn.games-workshop.com/wp-content/uploads/2017/06/Warhammer-40k-Battle-Primer-English.pdf page 6
Pistol
Pistols are carried one-handed and
can even be used in a melee to shoot
at point-blank range. Many warriors
carry one as a sidearm, alongside their
primary weapon.
A model can fire a Pistol even if there are
enemy units within 1" of its own unit, but
it must target the closest enemy unit. In
such circumstances, the model can shoot
its Pistol even if other friendly units are
within 1" of the same enemy unit.
Each time a model equipped with both a
Pistol and another type of ranged weapon
(e.g. a Pistol and a Rapid Fire weapon)
shoots, it can either shoot with its
Pistol(s) or with all of its other weapons.
Choose which it will fire (Pistols or nonPistols)
before making hit rolls.