1. An image processing apparatus for managing image data stored in a database, comprising: an input unit configured to input image data provided by reading a sheet; a count unit configured to count, from the input image data, a number of pages printed on the sheet; an extraction unit configured to extract, as page images, areas of the pages from the input image data; a registration unit configured to register, in the database, the extracted page images in association with the counted number of the pages; a retrieval unit configured to retrieve from the data base a page image similar to a query page image, from wherein the query page image is extracted by said extraction unit from query image data inputted by said input unit; a comparison unit configured to compare the number of pages stored in the database in association with the retrieved page image, and the number of pages counted by said count unit from the input query image data; and a storage control unit configured to store the query page image instead of the retrieved page image into the database, when the number of pages which is counted by said count unit from the input query image data is smaller than the number of pages stored in the database in association with the retrieved page image.