SQL:无法将动态变量设置为OFFSET

时间:2018-08-08 12:46:25

标签: php sql laravel web

我正在尝试将变量分配给OFFSET属性,我也尝试过concat,但操作不正确。第一个是我的原始代码,第二个是我尝试将变量连接到偏移量的位置。

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');

也请帮助我以更好的方式优化此代码。 这是我尝试进行连续测试的地方,但我失败了。

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) ');

0 个答案:

没有答案