What kind of X-ray diffraction are you taking about? It sounds like you are refering to powder X-ray diffraction. Comparing you diffraction pattern to a database file gives you a good idea about the sample. If it is exactly the compound from the literature all peaks have to be present and in principle also the intensities have to be accordingly as well.
You can also do Rietveld refinement of you PXRD data, this have confirm the structure as well but it needs more work then just comparing 2 files.
A better way would be to do single crystal diffraction, this gives you the best confirmation if you are looking at the same crystal structure.
Since you haven't told the compounds you are looking at it is hard to give any further answers from my point of view.
In addition to Dr. Janka and Tomar, FullProf is the best way to do it.
Actually JCPDS cards provide the known phases that identified up to now. There is always possibility that you have extra phases in your sample. These extra phases should be found by trying. And as Ms. Tomar said, not only the peaks but their intensities are also essential for fitting. And this can be possible with FullProf. There are several programs , I heard "Maud".
Although it has been written in other answers to other questions many time I want repeat it briefly: The JCPDS supports you with different information. The Bragg angles (or d-values) are related to the the crystal LATTICE. Small changes in composition will change the peak positions even if the distribution of atoms keeps unchanged. The other information is related to the crystal STRUCTURE (relatice position of atoms within the unit cell) which mainly effects whether a reflex becomes visible or not, i.e. the intensity of an interference. So it is possible to generate phases with a lattice with identical (or pseudo-symmetrical) parameters so that the reflex positions of both phases are absolutely identical. Then only the intensity can distinguish between both phases. This combination often works with JCPDS quite nicely, but with specific uncertainties since often phases are not really chemically ideal. But also the structure information (intensity) can be falsified, i.e. by sample preparation (textured materials), since there are also other effects influencing the intensity of relactions (except of the relative atomic positions in the unit cell). I would highly recommend to read one of the well availabel books about this topic. They havn't been published without any sense, since even one book does not cover entirely all these effects so that you cannot expect you will get a general answer and don't have to read these book. Please enter "Rietveld refinement" in one of the search engines like Google and I can promise you will be busy for the next two years only reading all the documents listed today (not those listed in two years). ReserachGate cannot replace these basic functions nowadays available.