简体   繁体   中英

Get Nearest Date in php

I have list of events so each event start date to end date so each event have list of schedules between events start date and end date I need to get only first nearest date I mean first event schedule date.

Here is my code

SELECT
  s.schedule_id, s.schedule_start_time, s.schedule_end_time, s.schedule_topic, s.Parallel,
  c.speaker_name
FROM schedule_table AS s, speaker_profile_table AS c
WHERE
  s.event_id='23'
  OR s.schedule_date LIKE '%2012-06-07%'
  AND c.speaker_id = s.speaker_id
ORDER BY s.schedule_start_time ASC

Here I get all schedules like this

schedule1:2012-06-06, schedule2:2012-06-06, schedule3:2012-06-08

Here I need only schedule1 and schedule2 only I don't need schedule3 how can i get this please guide me

Thanks for advance

If I understand what you want correctly, this should do the job ( EDITED ):

SELECT
  s.schedule_id, s.schedule_start_time, s.schedule_end_time, s.schedule_topic, s.Parallel,
  c.speaker_name
FROM schedule_table s
LEFT JOIN speaker_profile_table c ON c.speaker_id = s.speaker_id
WHERE s.schedule_date = (
  SELECT schedule_date
  FROM schedule_table
  WHERE
    event_id = '23'
    OR schedule_date LIKE '%2012-06-07%'
  ORDER BY schedule_date ASC
  LIMIT 1
)
ORDER BY s.schedule_start_time ASC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM