Search between dates in 2 columns of the same table

0

Colleagues.

I have a table that brings the beginning and the end of an event.

InicioEvento = 2016-06-01 07:00:00 
FimEvento = 2016-12-31 00:00:00

I know if I use BETWEEN, I can search between dates, but how would I do between dates with two columns? I tried that way, but I do not know if it's correct:

select * from eventos where  (inicio_eventos BETWEEN '2016-02-22 00:00:00' and '2016-12-31 00:00:00') and  (fim_eventos BETWEEN '2016-02-22 00:00:00' and '2016-12-31 00:00:00')
    
asked by anonymous 05.07.2016 / 17:11

1 answer

2

You should choose one of the columns to compare, or if you want to include the two, you could use "AND" in the comparison.

Where <campo_sql_1> Between InicioEvento AND FimEvento
  And <campo_sql_2> Between InicioEvento AND FimEvento
    
05.07.2016 / 17:22