0

I'm trying to assign a variable to OFFSET property I tried concat too but I'm not doing it right. First is my original code and the second one is where I've tried to concat the variable to the offset.

SELECT * FROM( SELECT id, title, content, userc_id, created_at, is_deleted FROM stories
UNION
SELECT id, heading AS title, description AS content, userc_id, created_at, is_deleted FROM causes
) AS a
JOIN (SELECT clients.* FROM clients) AS b ON a.userc_id = b.id
LEFT JOIN (SELECT files.* FROM files ) AS c ON c.table_id = a.id AND (c.table = "stories" OR c.table = "causes") 
WHERE a.is_deleted = 0
ORDER BY a.created_at
LIMIT 1
OFFSET $offset');

Please help to me to optimize this code a better way too. Here is where I've tried doing concat but I failed miserably.

SELECT * FROM( SELECT id, title, content, userc_id, created_at, is_deleted FROM stories
UNION
SELECT id, heading AS title, description AS content, userc_id, created_at, is_deleted FROM causes
) AS a
JOIN (SELECT clients.* FROM clients) AS b ON a.userc_id = b.id
LEFT JOIN (SELECT files.* FROM files ) AS c ON c.table_id = a.id AND (c.table = "stories" OR c.table = "causes") 
WHERE a.is_deleted = 0
ORDER BY a.created_at
CONCAT(LIMIT 1 OFFSET $offset) ');
rakesh shrestha
  • 1,335
  • 19
  • 37

0 Answers0