<Tr> <Th> Occupation </Th> <Td> Deputy Sheriff </Td> </Tr> <Tr> <Th> Family </Th> <Td> Sheriff Andy Taylor (friend) Opie Taylor (friend) Aunt Bee (friend) Thelma Lou (girlfriend) </Td> </Tr> <P> Bernard "Barney" P. Milton Oliver Fife is a fictional character in the American television program The Andy Griffith Show, portrayed by comic actor Don Knotts . Barney Fife is a deputy sheriff in the slow - paced, sleepy southern community of Mayberry, North Carolina . He appeared in the first five seasons (1960--65) as a main character, and, after leaving the show at the end of season five, made a few guest appearances in the following three color seasons (1965--68). He also appeared in the first episode of the spin - off series Mayberry R.F.D. (1968--1971), and in the 1986 reunion telemovie Return to Mayberry . Additionally, Barney appeared in the Joey Bishop Show episode, "Joey's Hideaway Cabin" and, unnamed, in the first episode of The New Andy Griffith Show . </P> <P> In 1999, TV Guide ranked him Ninth on its 50 Greatest TV Characters of All Time list . </P>

When did barney leave the andy griffin show