SELECT `oxv_oxarticles_2_de`.`oxid`, `oxv_oxarticles_2_de`.`oxshopid`, `oxv_oxarticles_2_de`.`oxparentid`, `oxv_oxarticles_2_de`.`oxvarstock`, `oxv_oxarticles_2_de`.`oxstock`, `oxv_oxarticles_2_de`.`oxstockflag`, `oxv_oxarticles_2_de`.`oxvarcount`, `oxv_oxarticles_2_de`.`oxvarname`, `oxv_oxarticles_2_de`.`oxtitle`, `oxv_oxarticles_2_de`.`oxvarselect`, `oxv_oxarticles_2_de`.`oxthumb`, `oxv_oxarticles_2_de`.`oxpic1`, `oxv_oxarticles_2_de`.`oxunitquantity`, `oxv_oxarticles_2_de`.`oxtprice`, `oxv_oxarticles_2_de`.`oxvat`, `oxv_oxarticles_2_de`.`oxvarminprice`, `oxv_oxarticles_2_de`.`oxskipdiscounts`, `oxv_oxarticles_2_de`.`oxprice`, `oxv_oxarticles_2_de`.`oxvarmaxprice`, `oxv_oxarticles_2_de`.`oxweight`, `oxv_oxarticles_2_de`.`oxunitname`, `oxv_oxarticles_2_de`.`oxshortdesc`, `oxv_oxarticles_2_de`.`oxpricec`, `oxv_oxarticles_2_de`.`oxartnum`, `oxv_oxarticles_2_de`.`oxbundleid`, `oxv_oxarticles_2_de`.`oxfreeshipping`, `oxv_oxarticles_2_de`.`oxnonmaterial`, `oxv_oxarticles_2_de`.`oxactive`, `oxv_oxarticles_2_de`.`oxicon`, oxv_oxarticles_2_de.oxtimestamp FROM oxv_oxcategories_2_de
LEFT JOIN oxv_oxobject2category_2 as oc ON oxv_oxcategories_2_de.oxid = oc.oxcatnid
LEFT JOIN oxv_oxarticles_2_de ON oxv_oxarticles_2_de.oxid = oc.oxobjectid
WHERE ( oxv_oxarticles_2_de.oxactive = 1 and oxv_oxarticles_2_de.oxhidden = 0 and ( oxv_oxarticles_2_de.oxstockflag != 2 or ( oxv_oxarticles_2_de.oxstock + oxv_oxarticles_2_de.oxvarstock ) > 0 ) and IF( oxv_oxarticles_2_de.oxvarcount = 0, 1, ( select 1 from oxv_oxarticles_2_de as art where art.oxparentid=oxv_oxarticles_2_de.oxid and art.oxactive = 1 and ( art.oxstockflag != 2 or art.oxstock > 0 ) limit 1 ) ) and ( ( ( select oxobjectrights.oxobjectid from oxobjectrights where oxobjectrights.oxobjectid = oxv_oxarticles_2_de.oxid and oxobjectrights.oxaction = 1 limit 1 ) is null ) ) ) and oxv_oxarticles_2_de.oxparentid = ''
AND oxv_oxcategories_2_de.OXLEFT >= '1'
AND oxv_oxcategories_2_de.OXRIGHT <= '660'
AND oxv_oxcategories_2_de.OXROOTID = 'ad8479f2542a33ba8.19039064'
Group by oxv_oxarticles_2_de.oxid
ORDER BY `oxv_oxarticles_2_de`.`OXARTNUM` asc , oc.oxpos, oc.oxobjectid