Answer the question
In order to leave comments, you need to log in
How to write SQL select?
Hello! Faced such a problem.
There are two tables: topic and topic_tag
and
They are related by topic_id
field
I need to select all elements from topic if it has one of given tags (For example, IN('website', 'demo', 'test'))
I tried to do So:
SELECT DISTINCT
t.topic_id
FROM
topic as t
JOIN topic_tag as tag on tag.topic_id = t.topic_id AND tag.topic_tag_text IN ('сотрудники', 'Директор')
WHERE
1=1
ORDER BY t.topic_id desc
LIMIT 0, 10
Answer the question
In order to leave comments, you need to log in
LIMIT <первая_запись>, <количество_записей>
Given that the records are numbered from 1, the selections LIMIT 0, 10
and are LIMIT 1, 10
equivalent.
You overdid it with the request. If you only need topic_id from 1 table, you don't need to join at all to do
SELECT t.topic_id FROM topic as t
WHERE
t.topic_id in (SELECT topic_id FROM topic_tag WHERE topic_tag_text IN ('employees', 'Director')) ORDER BY t. topic_id desc
Run a request in phpmyadmin and see how the limit is set there when switching pagination, it will be clear how you need to do it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question