ERROR:  syntax error at or near ")"
LINE 1: ...(select pid from ewf.gallery_title_pics where tid=) order by...
                                                             ^

select pth from ewf.images where id in(select pid from ewf.gallery_title_pics where tid=) order by id desc