Reputation: 9293
$stmt = $db->query("SELECT * FROM posts where pos in ('slider', 'right', 'below') limit " . $limit . " offset " . $offset);
This gives me posts where pos
is slider
or right
or below
with limit and offset params.
What I need is:
- select all posts with pos
= slider
or right
- without limit
and offset
- plus - posts with pos
= below
- using limit
and offset
params.
It can be done using twice $stmt
but I need to join the two selections for processing all selected posts at once.
UPDATE
I tried:
$stmt = $db->query("SELECT * FROM posts where pos in ('slider', 'right')
UNION
(SELECT * FROM posts where pos = 'below' limit 8");
Syntax error.
Any help?
Upvotes: 0
Views: 45
Reputation: 220
Union would work for you since both queries would return the same data set, you could then process all results at once.
$sql = "
(select all posts with pos = slider or right - without limit and offset)
UNION
(select all posts with pos = below - using limit and offset params)
;";
Upvotes: 1