Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mysql query syntax

Tags:

sql

php

mysql

I have these fields on my table

month
year

I wanted to make a query 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 doesn't give the right 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 variable, I showed actual number for you to understand easily :) any help?

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

like image 777
Samsan Phone Number Lookup Avatar asked Dec 01 '22 23:12

Samsan Phone Number Lookup


1 Answers

try this:

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

This will take care of all the scenarios.. even though difference between the years are more than one

like image 88
Joe G Joseph Avatar answered Dec 04 '22 04:12

Joe G Joseph