Answer the question
In order to leave comments, you need to log in
SELECT query with initial id?
There is a table with fields: id INT, name VARCHAR(255), date DATE.
How can I form a SELECT query sorted by the date field so that records start with a fixed id value?
Let me explain.
the entire table is sorted by date, while the id can go as you like, for example like this: 10, 20, 3, 40, 15, 1, 17. I need to get a bunch of rows with a query (LIMIT 10 for example), but so that each pack starts with a specific id. For example, you need with id=40, then there will be a sequence: 40, 15, 1, 17, etc.
Answer the question
In order to leave comments, you need to log in
If all dates in the table are unique, then the following query will do
: select * from tbl
where `date` >= (select `date` from tbl where id = 40)
order by `date`;
where will work just fine under these conditions:
select id,name,"DATE" from your_table order by "DATE",id,name where id>=N
You can try to do it with a subquery that will select by date, and the main query will filter id
But something tells me that you initially have something wrong with the architecture
Zprros
and
Absolutely identical in terms of the set of records that will be returned. Only the sorting of records will be changed. But records and there and there tezhe.
You need to understand that ORDER BY does not depend on WHERE. You can just do
AND again get the same records just not sorted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question