SELECT *
FROM tbl_company_names as names,
tbl_company_images_products as products,
tbl_page_up as page_up ,
tbl_material as material,
tbl_color as color
WHERE names.uniq_id = products.uniq_id
and names.users_login = products.users_login
and products.uniq_id = page_up.uniq_id
and products.users_login = page_up.users_login
and products.id_product = material.id_product
and products.id_product = color.id_product
and products.name_product = 5
and names.paid = 1
and products.checked = 0
and (
(material.products_part = 1 and material.materials_name IN(0,49))
or (material.products_part = 2 and material.materials_name IN(0))
or (material.products_part = 3 and material.materials_name IN(0,109))
)
and (
(color.products_part = 1 and color.colors_name IN(0,2))
or (color.products_part = 2 and color.colors_name IN(0))
)
group by material.id_product,color.id_product
having count(*) > 0
ORDER BY page_up.date_page_up DESC ;