This:
SELECT *
FROM employee
WHERE JoinDate >= '$input'
AND JoinDate <= '$input' + INTERVAL 7 DAY
or use BETWEEN
سؤال
I want to select value from database that start with a dynamic input like this
SELECT * FROM employee OFFSET JoinDate = '$input' LIMIT 7
I'd like to select all the field in employee table where JoinDate start from the input, let say from '25-03-2014' until 7 days later. But the offset is wrong. Could anyone help me?
المحلول
This:
SELECT *
FROM employee
WHERE JoinDate >= '$input'
AND JoinDate <= '$input' + INTERVAL 7 DAY
or use BETWEEN
نصائح أخرى
Is the table ordered by date? If you want to select the 7 records right after the search hit - I think you could do something like:
SELECT * FROM employee WHERE JoinDate >= '$input' LIMIT 7 ORDER BY JoinDate ASC;
If you want to select all dates within a range, you could:
SELECT * FROM employee WHERE JoinDate >= '$input' AND JoinDate <= '$input' + INTERVAL 7 DAY ORDER BY JoinDate ASC;
Use Interval:
SELECT * FROM employee WHERE JoinDate >= '$input' AND JoinDate <= '$input' + INTERVAL 7 DAY