........S. [ZBXNEXT-2519] replaced 0/1 with ZBX_API_FALSE/ZBX_API_TRUE, reorganized sql statements to use joins (applying distinct when necessary)