Answer the question
In order to leave comments, you need to log in
How to select 20 records by condition?
I need to select with an id, say 300 20 records that pass by the condition: if at least one tag (eng, anime, history) is included in the tags record field.
Here's what I've come up with so far: SELECT * FROM memes LIMIT 20 OFFSET {last_id - 21}
I don't know how to write the condition. I need to return 20 records that pass by a condition.
Answer the question
In order to leave comments, you need to log in
Just substrings, but then you will find not tags, but substrings:
SELECT * FROM memes WHERE tags LIKE '%eng%' AND tags LIKE '%history%' AND tags LIKE '%anime%' ORDER BY id DESC LIMIT 20
SELECT * FROM memes WHERE tags LIKE '% eng %' AND tags LIKE '% history %' AND tags LIKE '% anime %' ORDER BY id DESC LIMIT 20
SELECT * FROM memes WHERE tags LIKE '% rus\_eng %' ESCAPE "\" AND tags LIKE '% 100\% %' ESCAPE "\" ORDER BY id DESC LIMIT 20
SELECT * FROM memes WHERE tags LIKE '%,eng,%' AND tags LIKE '%,history,%' AND tags LIKE '%,anime,%' ORDER BY id DESC LIMIT 20
SELECT * FROM memes WHERE instr(tags, ',eng,') AND instr(tags, ',history,') AND instr(tags, ',anime,') ORDER BY id DESC LIMIT 20
SELECT * FROM memes WHERE instr(tags, ' eng ') AND instr(tags, ' history ') AND instr(tags, ' anime ') ORDER BY id DESC LIMIT 20
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question