It is poorly understood how sensory systems memorize the intensity of sensory stimulus, compare it with a newly sensed stimulus, and regulate the orientation behaviour based on the memory. Here we report that Caenorhabditis elegans memorizes the environmental salt concentration during cultivation and exhibits a strong behavioural preference for this concentration. The right-sided amphid gustatory neuron known as ASER, senses decreases in salt concentration, and this information is transmitted to the postsynaptic AIB interneurons only in the salt concentration range lower than the cultivation concentration. In this range, animals migrate towards higher concentration by promoting turning behaviour upon decreases in salt concentration. These observations provide a mechanism for adjusting the orientation behaviour based on the memory of sensory stimulus using a simple neural circuit.