I have one table for posts where I save the type of each post in one field. Lets say I have two types – “type1” and “type2”. I need to retrieve latest x posts from that table where x/2 posts are from “type1” and the other half is from “type2”. How is that possible using one mysql query?
Share
Ok so, your table is like this:
And you want to retrieve some number (x) of posts where half of them will be of type 1 and the other half of type 2?
One possible solution is this:
Of course the limit quantity should be half the desired quantity X.
This returns: