A system and method for retrieving musical information from a database based on a melody fragment. The system may be used by a person without formal musical training to retrieve musical data (e.g., the name of a song, bibliographic information about a song, or the song itself) from a database by providing the melody or fragment of the melody of the desired music to a computer interface. The melody may be provided by singing, humming, whistling, or playing a musical instrument, for example, a keyboard. The inputted melodic information is encoded using relative changes in pitch and rhythm throughout the melody. The encoded information is then compared using a matching algorithm to similarly encoded melodic information representative of many musical pieces (e.g., songs). Results may also be sorted using a weighted algorithm.