There have been a number of versions of the game (editions, systems, whatever).
With some simplification, for present purposes, they can be broken down into:
(1.) OD&D (1974 version)
(2.) OD&D (1974) + Supplements (Greyhawk, Blackmoor, etc.)
(3.) Basic/Expert/Rules Cyclopedia D&D (sometimes incorrectly called 'OD&D')
(4.) 1E AD&D
(5.) 1E AD&D + Unearthed Arcana
(6.) 2E AD&D
(7.) 2E AD&D + Various 'Options' Books
(8.) 3E D&D
(9.) Hackmaster
(10.) Castles and Crusades
I would say that there are pretty strong similarities between versions (2.) through (6.). (Possibly 7 as well, but I am not familiar enough with any of the optional material for 2e to comment.). These similarities are strong enough that material for any of these systems can be used with any other of these systems will very little work. I would also include Castles and Crusades (10.) in this group, in terms of 'system compatibility', even though it does not share the name 'D&D' with the others. (It is very easy to convert material from 1e AD&D, 2e AD&D, or B/X/RC AD&D into C&C.)
In contrast, (1.) and (8.) differ quite a bit from (2.) - (6.).
Hackmaster (9.) resembles (4.), (5.), and (6.) far more than (8.).
Castles and Crusades (10.) resembles (2.), (3.), and (4.) far more than (8.).
In terms of its mechanics, (8.) is the most different/unique.
Which versions of the above systems get to be called 'Dungeons and Dragons' is purely a legal matter.
Which version of the above systems is 'best' depends on the interests and tastes of the group in question.
(I pretty much made this exact point in another thread -- and yet strangely was called a 'troll' for doing so.)