A one-pot, three-component cascade reaction between unprotected sugars, primary amines, and 3-oxoacetonitriles gave N-substituted 2,3,5-functionalized pyrroles or N-substituted 2,3,4-functionalized pyrroles in excellent yields and selectivities. The selectivity of the reaction was achieved by simple control of the sequence of substrate addition. The reaction showed a wide substrate scope, and various types of sugars, primary amines, and oxoacetonitriles reacted smoothly. The work demonstrates a highly desired simple reaction for embedding nitrogen into sugars to produce valuable N-heterocyclic compounds that are amenable to further modifications to natural products and drug intermediates.