Although most shows are self contained fictional worlds that exist separate from the rest of TV, there are some that actually connect to other shows in pretty unexpected ways.
Sometimes this happens due to the nature of spinoffs. The whole concept here is that the creators take a character from one show and give him his own series which takes place in the same world. So Frasier exists in the same fictional setting as Cheers, with plenty of overlapping characters, but not the same fictional setting as Friends. It's just like how Iron Man shares a universe with Captain America but not with Batman. In the Frasier universe, Sam Malone and Norm Peterson exist, but Joey Tribbiani doesn't.
Another way this can happen is through a crossover event, where two shows come together into one. Family Guy and American Dad had a fun crossover in one episode, so that means that Peter Griffin lives in the same world that Stan Smith inhabits. By doing this, the creators are implying this larger fictional universe that encompasses multiple shows, even if the crossover is mostly just for comedy purposes.
This is quite common on TV, though it's often so subtle that a lot of viewers don't even notice. Sometimes characters pop up in multiple shows as a way of connecting them all, while other times characters will reference products or events from another series.
Here are 10 shows you didn't even realise actually take place in the same universe.