Products

select DISTINCT p.CatalogId,p.cname from products p, prodcategories cc, categories c where cc.intCatalogId=p.CatalogId and cc.intcategoryid=c.categoryid AND p.hide = 0 and (p.customermatch is null or p.customermatch = '') and (p.loggedin = 0 or p.loggedin is null) and (c.customermatch is null or c.customermatch = '') and (c.loggedin = 0 or c.loggedin is null) AND (higherCatalogId is null) order by p.cname