select imgId, ImgTitle, ImgDescription, FileSize , fileExt, sortRank, contentId, contentPath, imageThumb, uploadDate, fileWidth, fileHeight, hrfilesize, hrWidth, hrHeight, highResCntId , categoryId from qcf_dispImageFiles union select imgId, ImgTitle, ImgDescription, FileSize, fileExt, sortRank, contentId, contentPath, imageThumb, uploadDate, fileWidth, fileHeight, hrfilesize, hrWidth, hrHeight, highResCntId 0 as categoryId from qmd_productImages order by sortRank, imgTitle select distinct imgId, ImgTitle, ImgDescription, FileSize, fileExt, sortRank, contentId, contentPath, imageThumb, uploadDate, fileWidth, fileHeight, hrfilesize, hrWidth, hrHeight, highResCntId from qmd_combinedResources where categoryId not in () order by sortRank, imgTitle