Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Infinite looping
Processing trees with recursive CTEs
Processing graphs with recursive ctes
28. Traveling salesman 1


Okay! Quite an impressive query, wasn't it? Let's build it, step by step, from scratch now.


We start in London, so let's show the information for London first. We need the following columns:

  • Path – for now, it's simply the city name,
  • Lat,
  • Lon,
  • TotalDistance – the total distance travelled between cities – for now it's equal to 0.0,
  • CountPlaces – the number of cities visited; it's equal to 1 at this point.

All the information can be found in the City table.