I need to count a distinct tile where it meets certain criteria. However, if one of the items in that tile is a different category, then I should not count the tile. I tried using distinct but I still get the count as each tile has 2-5 lines in the database. I join two tables and end up with a table Main that has each Tile, Batch, Order Number, Item Number and quantity. There are other columns but they don't matter.