F
F
FMars2015-09-19 14:44:52
MySQL
FMars, 2015-09-19 14:44:52

How to make such a SQL query?

It is necessary to make request in which records which are intersected by the periods will get to selection.
For example, if I am looking for records from 2015-10-05 to 2015-10-10, then the second line will fall into the selection (see picture), it should also fall if I am looking for from 2015-10-15 to 2015-10-20, For example.
9e57583649cb4857b2d328b02af6592c.jpgxzfsbgcgnxtebsxb.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Fedoseev, 2015-09-19
@FMars

from <= end_date and to >= start_date
all cases seem to be covered

T
Therapyx, 2015-09-19
@Therapyx

here is an example but it is MS SQL

ALTER Procedure [dbo].[Procedure_Name] (		
    @SelectByDate1 date = null,
    @SelectByDate2 date = null	
  ) as

   select * 
   from Table_Name
   where 
   P_Date >= coalesce(@SelectByDate1, p_Date) 
   and P_Date <= coalesce(@SelectByDate2, p_Date) 	
   order by p_date desc

In this case, there are 2 textboxes. If they are empty, then select *
from Table_Name. and depending on the filling of dates, variables with sorting between dates will already be connected to the textboxes. As you can see there P_Date >= and and P_Date <= even if 1 day falls under this interval, it is displayed.
in MySQl, unfortunately, I don't know if there is "coalesce"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question