Which D D expansion is the best

Short answer: To get all the "official" things you can use for player characters, buy the Players' Handbook (PHB), Xanathar's Guide to Everything (XGtE), Dungeon Masters' Guide (DMG), Mordenkainen’s Tome of Foes (MToF), and Volo's Guide to Monsters (VGtM). Also download the Elemental Evil Players' Companion (EEPC) (because Aarakocra and Genasi are not available in any other book).

Note that the DMG, MToF and VGtM books are primarily for those running games but do contain some character options.

Depending on the game you are in, you may or may not consider Sword Coast Adventurer's Guide (SCAG), The Tortle Package, Wayfinder's Guide to Eberron (WGtE), and the Guildmasters' Guide to Ravnica (GGtR) to be "official". These are setting-specific books (the first two are for the Forgotten Realms).

There are character options in the Aquisitions Incorporated source book, but I'm not sure if you'd consider that "official" as it is a fairly different game from D&D 5E.

To summarise player-character-oriented rules:

D&D Basic Rules (free)

This is a subset of the rules in the PHB, designed as a free introduction to the game. As well as character and game rules, it contains some monsters and magic treasure and advice on running a game.

  • Races
    • Dwarf: Hill, Mountain
    • Elf: High, Wood
    • Halfling: Lightfoot, Stout
    • Human
  • Classes
    • Cleric: Life domain
    • Fighter: Champion archetype
    • Rogue: Thief archetype
    • Wizard: Evocation school
  • Spells: Cleric and Wizard.
  • Backgrounds: Acolyte, Criminal, Folk Hero, Noble, Sage, Soldier

Player's Handbook

  • Races
    • Dwarf: Hill, Mountain
    • Elf: High, Wood, Dark
    • Halfling: Lightfoot, Stout
    • Human
    • Gnome: Forest, Rock
    • Half-Elf
    • Half-Orc
    • Dragonborn
    • Tiefling
  • Classes
    • Barbarian: Berserker, Totem Warrior
    • Bard: Lore, Valor
    • Cleric: Knowledge, Life, Light, Nature, Tempest, Trickery
    • Druid: Land, Moon
    • Fighter: Champion, Battle Master, Eldritch Knight
    • Monk: Open Hand, Shadow, Four Elements
    • Paladin: Devotion, Ancients, Vengeance
    • Ranger: Hunter, Beast Master
    • Rogue: Thief, Assassin, Arcane Trickster
    • Sorcerer: Draconic Bloodline, Wild Magic
    • Warlock: Archfey, Fiend, Great Old One
    • Wizard: Abjuration, Conjuration, Divination, Enchantment, Evocation, Illusion, Necromancy, Transmutation
  • Spells for all classes
  • Backgrounds: Acolyte, Charlatan, Criminal, Entertainer, Folk Hero, Guild Artisan, Hermit, Noble, Outlander, Sage, Sailor, Soldier, Urchin.
  • Feats

Xanathar's Guide to Everything

  • Classes:
    • Barbarian: Zealot, Storm Herald, Ancestral Guardian
    • Bard: Glamour, Swords, Whispers
    • Cleric: Forge, Grave
    • Druid: Dreams, Shepherd
    • Fighter: Samurai, Cavalier, Arcane Archer
    • Monk: Drunken Master, Kensei, Sun Soul (also in SCAG)
    • Paladin: Conquest, Redemption
    • Ranger: Horizon Walker, Monster Slayer, Gloom Stalker
    • Rogue: Inquisitive, Mastermind, Scout, Swashbuckler (also in SCAG)
    • Sorcerer: Divine Soul, Shadow, Storm (also in SCAG)
    • Warlock: Celestial, Hexblade, and several new Eldritch Invocations that can be used by any subclass.
    • Wizard: War Mage
  • Feats
  • Spells (including those first printed in the EEPC).

Elemental Evil Player's Companion (free)

This information (except Deep Gnome and Goliath) is also contained in the Princes of the Apocalypse adventure book. The idea of the free download is that players can use the material without having to purchase the book.

  • Races
    • Aarakocra
    • Gnome: Deep (also in SCAG and MToF)
    • Genasi: Earth, Air, Fire, Water (also in the appendix of the Princes of the Apocalypse adventure)
    • Goliath (also in VGtM)
  • Spells: Bards, Druids, Rangers, Sorcerers and Warlocks, Wizards (not Clerics or Paladins).

Dungeon Master's Guide

While primarily for DMs, this book has a few player options.

  • Classes
    • Paladin: Oathbreaker oath
    • Cleric: Death domain
  • Races
    • Aasimar (this is different from the Aasimar in VGtM)
    • Eladrin (this is different from the Eladrin in MToF)

Mordenkainen’s Tome of Foes

  • Races
    • Dwarf: Grey (Duergar)
    • Elf: Eladrin, Sea Elf, Shadar-Kai.
    • Gith: Githyanki, Githzerai
    • Gnome: Svirfneblin (Deep Gnome) (also in SCAG and EEPC)

Volo's Guide to Monsters

  • Races
    • Aasimar
    • Firbolg
    • Goliath (also in EEPC)
    • Kenku
    • Lizardfolk
    • Tabaxi
    • Triton
    • Short notes on monstrous characters, including Bugbear, Goblin (also in GGtR), Hobgoblin, Kobold, Orc, and Yuan-ti Pureblood

Sword Coast Adventurer's Guide

Resources for games set in the Sword Coast region of the Forgotten Realms,

  • Races
    • Dwarf: Grey (Duergar)
    • Gnome: Deep (also in EEPC)
    • Additional options for Half-Elf and Tiefling
  • Classes
    • Barbarian: Elk and Tiger totems for Barbarian Totem Warrior, Battlerager path
    • Cleric: Arcana
    • Fighter: Purple Dragon Knight
    • Monk: Way of the Long Death, Way of the Sun Soul (also in XGtE)
    • Paladin: Oath of the Crown
    • Rogue: Mastermind, Swashbuckler (also in XGtE)
    • Sorcerer: Storm (also in XGtE)
    • Warlock: The Undying
    • Wizard: Bladesinger
  • Spells: Four cantrips for Sorcerers, Warlocks and Wizards.
  • Backgrounds: City Watch, Clan Crafter, Cloistered Scholar, Courtier, Faction Agent, Far Traveler, Inheritor, Knight of the Order, Mercenary Veteran, Urban Bounty Hunter, Uthgardt Tribe Member, Waterdhavian Noble

The Tortle Package

Resources for games set in the Snout of Omgar in the Forgotten Realms (a region briefly described in Tomb Of Annihilation).

Wayfinder's Guide to Eberron

Resources for games set in the Eberron campaign world.

  • Races
    • Changeling
    • Kalashtar
    • Shifter
    • Warforged
    • Lots of subraces for the PHB races
    • Marks (a way of customising a race with a magical effect)
  • Backgrounds: House Agents for the 13 major Houses

Guildmasters' Guide to Ravnica

Resources for games set in the Ravnica campaign world (the world of Magic the Gathering).

  • Classes
    • Cleric: Order
    • Druid: Circle of Spores
  • Races
    • Centaur
    • Loxodon
    • Minotaur
    • Simic Hybrid
    • Vedalken
  • Backgrounds: Boros Legionnaire, Dimir Operative, Golgari Agent, Gruul Anarch, Izzet Engineer, Orzhov Representative, Rakdos Cultist, Selesnya Initiate, Simic Scientist

Online Supplements

There are Online Supplements for some of the hardback adventures, containing magic items, monsters and spells that are used in the adventure, so that you don't have to buy all the compendiums.

Curse of Strahd doesn't have an online supplement but does have a player options document with a new background and some gothic trinkets. It also has some downloadable maps and handouts.

Ghosts of Saltmarsh includes some new backgrounds but does not have a downloadable supplement or player options document.

Download links: Hoard of the Dragon Queen, Rise of Tiamat, Princes of the Apocalypse, Out of the Abyss, Curse of Strahd, Storm King's Thunder, Tomb of Annihilation.

Also consider Unearthed Arcana

Extra rules, including classes, that might end up in a future rulebook, presented for the community to preview and critique.

Personal note: I don't own Guildmasters' Guide to Ravnica and Wayfinder's Guide to Eberron. I filled in the items above based only on the ToC.