And it does seem as if this is an old riddle, with many variations. The basic riddle relies on the fact that the name of the town of Athy in County Kildare is pronounced ‘a-THIGH’, which opens up numerous punning opportunities.
The Freeman’s Journal of 24 September 1874 has this version, cited itself from the Hornet (published in London between 1867 and 1880):
Latest from Guy’s. – What town in Ireland would be most valuable for a medical student? Athy. (A thigh, don’t you see?).
The Sunday Independent knows another twist (22 December 1907):
Why was Carn-sore? - Because he had lost Athy (a thigh).
Joyce suggests that there are unprintable versions. Perhaps he was thinking of this variation, collected by a 'Dr. Susruta' amongst British (presumably Irish) troops in Central India and published in Anthropophyteia, a yearbook publication covering popular culture with a strong slant towards sexual and erotic themes (1911, VIII. 394):
In what town can one enjoy a woman best? – In Athy (a thigh), for that’s near the middle of the Queen’s County (cuntie).
Search by keyword (within this site): Puzzles Wordplay