A molecular formula is the same as its empirical formula if, in the molecular formula, the ratio of the number of each atom in the formula is non-reducible. That is to say, there is no common (whole number) factor between the subscripts on the atoms in the formula.
Take, for example, barium iodide, #"BaI"_2#. The ratio of the atoms in the formula is #1 "(barium)": 2 "(iodine)"#. Is there a common factor of #1# and #2# that would allow these numbers to be reduced to simpler terms? No. Therefore, the empirical formula and the chemical formula of barium iodide are the same.
Now let's look at glucose, #"C"_6"H"_12"O"_6#. The ratio of the atoms in the formula is #6 "(carbon)": 12 "(hydrogen)": 6 "(oxygen)"#. Is there a common factor of #6#, #12#, and #6# that would allow these numbers to be reduced to simpler terms? Yes there is, #6#. If we divide each subscript in the formula by #6#, our new empirical formula is #"CH"_2"O"#. Thus, in this case the empirical and molecular formulas are not identical.
#"CH"_2"O"# is a popular empirical formula in organic chemistry; all monosaccharide sugars can be reduced to this empirical formula. There is a real compound that has a molecular formula of #"CH"_2"O"# as well, called formaldehyde (sometimes called methanal, systematically), the simplest of the group of organic compounds known as aldehydes (you can see where it was derived from).