Mysql php query syntax

I have these fields in a table

month year 

I wanted to make a request based on this

 month BETWEEN 4 AND 12 AND year = 2008 

OR

 month BETWEEN 1 AND 10 AND year is greater than 2008 but equal or less than 2009 

I tried this but did not give the correct query result.

 "WHERE month BETWEEN 4 AND 12 AND year = 2008 OR month BETWEEN 1 AND 10 AND year 2008<=2009"; 

NOTE: the numbers here are variables, I showed the actual number so you can easily understand :) any help?

year = (2008 <= 2009) means that the year must be greater than 2008, but equal to or less than 2009

+4
source share
5 answers

try the following:

 where (year*100)+month between 200804 and 200910 

This will take care of all the scenarios .. although the difference between the years is more than one

+10
source
 "WHERE ((month BETWEEN 4 AND 12) AND year = 2008) OR ((month BETWEEN 1 AND 10) AND (year 2008 OR 2009))"; 

hope this helps :)

+5
source

You have to do it

 WHERE (year = 2008 AND month BETWEEN 4 AND 12) OR (year > ? AND year <= 2009 AND month BETWEEN 1 AND 10) 

What do you mean by that? greater than 2008 but equal or less than 2009 . Do you mean the meaning of 2009 ?

+2
source

Have you looked at MySQL Date Functions ? Do it like trying to hammer a nail with a shoe.

+1
source

It should work as follows:

 WHERE ((month BETWEEN 4 AND 12) AND year = 2008) OR ((month BETWEEN 1 AND 10) AND year = 2009) 
+1
source

Source: https://habr.com/ru/post/1432019/


All Articles