It's all right. You do not need distinct
, there is no reason to duplicate result (unless there is a possibility of having equal photos in this table with different ids, which is the problem of having an unnatural PK). If you only want to know how many, use count:
select count(1) from tbl_fotos
where int_IDProduto not in (Select int_ID from tbl_produtos);
If every photo should be linked to a valid product or to none, you should probably have the FK constraint there:
ALTER TABLE tbl_fotos ADD CONSTRAINT [FK_fotos_produtos] FOREIGN KEY(int_IDProduto)
REFERENCES tbl_produtos (int_ID);
Then, in that case, finding how many photos without products would just be
select count(1) from tbl_fotos where int_IDProduto is null;
If the idea is that there are no photos that are not linked to products, in addition to creating the above constraint you should pass the column to not accept null:
ALTER TABLE tbl_fotos ALTER COLUMN int_IDProduto INT NOT NULL;
In any case, to know the IDs of the photos, just replace count(1)
with int_ID
.