使用 时,如果您有特定的顺序,limit
则应始终包含一个。order by
我认为您想要的查询是:
select * from passeio where ID not in
( select * from (
select ID from passeio where passeio_date > $date order by passeio_date asc LIMIT 1
UNION ALL
select ID from passeio where passeio_date < $date order by passeio_date desc LIMIT 1
)t
)
I also switched the union
to a union all
because you do not need to eliminate duplicates.
Perhaps a more efficient way to do this is:
select *
from passeio
where passeio_date > $date
order by passeio_date
limit 1, 1000000000
union all
select *
from passeio
where passeio_date < $date
order by passeio_date desc
limit 1, 1000000000
Whether this is more or less efficient depends on the data structure, but it eliminates the anti-join and doesn't require having an ID.