The current paradigm to explain the presence of Jupiters with small orbital periods (P $<$ 10 days; hot Jupiters) that involves their formation beyond the snow line following inward migration, has been challenged by recent works that explored the possibility of in situ formation. We aim to test whether stars harbouring hot Jupiters and stars with more distant gas-giant planets show any chemical peculiarity that could be related to different formation processes. Our results show that stars with hot Jupiters have higher metallicities than stars with cool distant gas-giant planets in the metallicity range +0.00/+0.20 dex. The data also shows a tendency of stars with cool Jupiters to show larger abundances of $alpha$ elements. No abundance differences between stars with cool and hot Jupiters are found when considering iron peak, volatile elements or the C/O, and Mg/Si ratios. The corresponding $p$-values from the statistical tests comparing the cumulative distributions of cool and hot planet hosts are 0.20, $<$ 0.01, 0.81, and 0.16 for metallicity, $alpha$, iron-peak, and volatile elements, respectively. We confirm previous works suggesting that more distant planets show higher planetary masses as well as larger eccentricities. We note differences in age and spectral type between the hot and cool planet hosts samples that might affect the abundance comparison. The differences in the distribution of planetary mass, period, eccentricity, and stellar host metallicity suggest a different formation mechanism for hot and cool Jupiters. The slightly larger $alpha$ abundances found in stars harbouring cool Jupiters might compensate their lower metallicities allowing the formation of gas-giant planets.