MYSQL query date range and any other date in the same query

Asked

Viewed 26 times

-2

I have the following dates as an example:

2021-06-01 2021-06-02 2021-06-03 2021-06-04 2021-06-05

would like to display 2021-06-01, 2021-06-02, 2021-06-03 and 2021-06-05

I am trying to do it this way: SELECT * FROM funci WHERE data >= '2021-06-01' && data <= '2021-06-03' && data = '2021-06-05' Returns Empty.

If removed: && date = '2021-06-05' returns me the range normally. What can be done differently? Thanks...

Clarify my doubt better:SELECT data FROM tab.. WHERE data BETWEEN '2021-06-01' AND '2021-06-03' && data = '2021-06-05'

I would like to return the dates within the range and another date outside the range

  • ( ( D >= x AND D <= y ) OR D = z )

1 answer

-2

From what I understand, you are trying to retrieve dates that are between the range 2021-06-01 and 2021-06-05, and that are not equal to 2021-06-04. For this situation the BETWEEN should work. Try something like:

SELECT * FROM funci WHERE data BETWEEN CONVERT("2021-06-01", DATE) AND CONVERT("2021-06-05", DATE) AND data <> CONVERT("2021-06-04", DATE);

  • Actually I want to return all the dates of the interval + another date that is not within the range

  • In this case, try to exchange AND for OR: SELECT * FROM funci WHERE data between CONVERT("2021-06-01", DATE) AND CONVERT("2021-06-03", DATE) OR data = CONVERT("2021-06-05", DATE);

  • Thank you... worked with your example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.