Get records between two date range in MYSQL

D.Madu

I have a table in my mysql db. This is my table.

material       sorg      f_date       t_date
2000012        2100    2016-05-01   2016-05-30
2000013        2100    2016-05-01   2016-05-21
2000021        2200    2016-05-01   2016-05-30
2000151        2100    2016-05-01   2016-05-15
2000336        2300    2016-05-01   2016-05-04
2000366        2300    2016-05-01   2016-05-24
2000451        2400    2016-05-01   2016-05-30
2000493        2200    2016-05-01   2016-05-11

I want to get material between two given date(f_date and t_date).

This is my query...

SELECT tbl_fast_goods.material from tbl_fast_goods WHERE f_date >= '2016-05-23' AND t_date <= '2016-05-29'

The output should be.

2000012, 2000021, 2000366, 2000451

But the problem is no output is given.

Blank

I think you want this, you just mistook the column.

SQL Fiddle

MySQL 5.6 Schema Setup:

CREATE TABLE tbl
    (`id` int, `user_id` int, `weather_type` varchar(5))
;

INSERT INTO tbl
    (`id`, `user_id`, `weather_type`)
VALUES
    (1, 12, 'cloud'),
    (2, 12, 'rain'),
    (3, 12, 'clear'),
    (4, 14, 'rain'),
    (5, 15, 'clear')
;


CREATE TABLE tbl_fast_goods 
    (`material` int, `sorg` int, `f_date` datetime, `t_date` datetime)
;

INSERT INTO tbl_fast_goods 
    (`material`, `sorg`, `f_date`, `t_date`)
VALUES
    (2000012, 2100, '2016-05-01 00:00:00', '2016-05-30 00:00:00'),
    (2000013, 2100, '2016-05-01 00:00:00', '2016-05-21 00:00:00'),
    (2000021, 2200, '2016-05-01 00:00:00', '2016-05-30 00:00:00'),
    (2000151, 2100, '2016-05-01 00:00:00', '2016-05-15 00:00:00'),
    (2000336, 2300, '2016-05-01 00:00:00', '2016-05-04 00:00:00'),
    (2000366, 2300, '2016-05-01 00:00:00', '2016-05-24 00:00:00'),
    (2000451, 2400, '2016-05-01 00:00:00', '2016-05-30 00:00:00'),
    (2000493, 2200, '2016-05-01 00:00:00', '2016-05-11 00:00:00')
;

Query 1:

SELECT tbl_fast_goods.material
from tbl_fast_goods
WHERE t_date >= '2016-05-23' AND f_date <= '2016-05-29'

Results:

| material |
|----------|
|  2000012 |
|  2000021 |
|  2000366 |
|  2000451 |

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

To get records in between two date in mysql

From Dev

Mysql : Get segmented records between multiple date range

From Dev

MySQL get ids of the range between two conditions

From Dev

Finding records between date range

From Dev

Finding records between date range

From Dev

MySQL: Proper date range between start and end date as two fields

From Dev

How to get date range between two date in Google AppMaker?

From Dev

MySQL get number of records in each day between two given dates

From Dev

Count of active records between date range

From Dev

PHP Mysql PDO retrieve records by date range

From Dev

MYSQL combine view of two table having different number of entry records in date range

From Dev

Mysql: Get no of records for todays date

From Dev

Get the MAX date between a range

From Dev

php MySQL query between two date time but include minutes from outside range if finish in range

From Dev

get records having admission date in a range

From Dev

get records having admission date in a range

From Dev

Get records between by range in Laravel 5.2

From Dev

Get user who have valid records within date range using mysql

From Dev

Fetching records between two date ranges

From Dev

mysql - how to get a random time (not date) between two time ranges

From Dev

If Get-Date is between a date range

From Dev

MySQL Date and Interval - records between dates

From Dev

SQL Count Age between two date range

From Dev

Iterate between two date range using Joda

From Dev

Split weeks between two date range

From Dev

Get Records of two tables with same date

From Dev

Retrieve records between two dates in mysql?

From Dev

MYSQL order NULL between two particular records

From Dev

MySQL return All records between two dates

Related Related

  1. 1

    To get records in between two date in mysql

  2. 2

    Mysql : Get segmented records between multiple date range

  3. 3

    MySQL get ids of the range between two conditions

  4. 4

    Finding records between date range

  5. 5

    Finding records between date range

  6. 6

    MySQL: Proper date range between start and end date as two fields

  7. 7

    How to get date range between two date in Google AppMaker?

  8. 8

    MySQL get number of records in each day between two given dates

  9. 9

    Count of active records between date range

  10. 10

    PHP Mysql PDO retrieve records by date range

  11. 11

    MYSQL combine view of two table having different number of entry records in date range

  12. 12

    Mysql: Get no of records for todays date

  13. 13

    Get the MAX date between a range

  14. 14

    php MySQL query between two date time but include minutes from outside range if finish in range

  15. 15

    get records having admission date in a range

  16. 16

    get records having admission date in a range

  17. 17

    Get records between by range in Laravel 5.2

  18. 18

    Get user who have valid records within date range using mysql

  19. 19

    Fetching records between two date ranges

  20. 20

    mysql - how to get a random time (not date) between two time ranges

  21. 21

    If Get-Date is between a date range

  22. 22

    MySQL Date and Interval - records between dates

  23. 23

    SQL Count Age between two date range

  24. 24

    Iterate between two date range using Joda

  25. 25

    Split weeks between two date range

  26. 26

    Get Records of two tables with same date

  27. 27

    Retrieve records between two dates in mysql?

  28. 28

    MYSQL order NULL between two particular records

  29. 29

    MySQL return All records between two dates

HotTag

Archive