Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id | employment_date | name
- -------------------------------
- 23 | 1980-01-11 | peter
- 21 | 1980-09-02 | sandra
- 34 | 1982-04-12 | steven
- 4 | 1982-06-14 | claudia
- 45 | 1983-10-12 | chuck
- 56 | 1984-03-16 | bob
- 1 | 1987-03-23 | kevin
- (
- SELECT id,@basedate:=employment_date AS employment_date,name
- FROM employees WHERE name='claudia'
- )
- UNION
- (
- SELECT * FROM employees
- ORDER BY if (employment_date>@basedate,employment_date,'9999-12-31') ASC
- LIMIT 2
- )
- UNION
- (
- SELECT * FROM employees
- ORDER BY if (employment_date<@basedate,employment_date,'0001-01-01') DESC
- LIMIT 2
- )
- ORDER BY employment_date ASC
Advertisement
Add Comment
Please, Sign In to add comment