SELECT p.*, p.id AS pid, "public" AS `type` FROM posts p left join post_attachments pa on pa.post_id = p.id where pa.type = ...