UPDATE tetel SET hasznalatban = 1 WHERE kod in (SELECT kod FROM tetel WHERE hasznalatban = 0 AND kod in (SELECT tetel_kod FROM (SELECT tetel_kod FROM tetel_raktar WHERE keszlet > 0) data GROUP by 1));