SELECT b.id AS buyId, b.itemFk, b.entryFk, CAST(b.buyingValue AS DECIMAL(10,2)) AS price, b.quantity, i.id, i.description, i.name AS itemName, i.subName, i.size AS itemSize, i.typeFk AS itemTypeFk, i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7, i.tag8, i.value8, i.tag9, i.value9, i.tag10, i.value10, it.id, it.workerFk, it.categoryFk, it.code AS itemTypeCode FROM buy b JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk WHERE b.entryFk IN(?) AND b.quantity > 0 ORDER BY i.typeFk , i.name