Hello Reader's if you are learning, optimizing the mysql query then in this blog you will know some new syntax offered by Mysql where you can make your query fast. Lets see the examples as below:-
In the code below, the results selects all schools results which having cityid BETWEEN 10 and 20, but products with a CategoryID of 1,2, or 3 should not be displayed:
SELECT * FROM school
WHERE (city id BETWEEN 10 AND 20)
AND NOT status IN (1,2,3);
In the second line you can see the syntax "BETWEEN", this is used when you have all results between two numbers so this makes you to get ride out of fetching single - single results at a time.
Now consider the SQL statement this will select all the school having the name starting between J and V. This code works perfect for both number and alphabets.
SELECT * FROM schole
WHERE schoneName BETWEEN 'J' AND 'V';
Just unlike it you can also use the unlike syntax for getting the not in given value and its code will go like this:-
SELECT * FROM schools
WHERE schoolNameNOT BETWEEN 'H' AND 'Z';
Now lets consider another example. Suppose you have a table full of entries of sellings and you want to get only the selected results between two dates. So as same you just have to use same "BETWEEN" syntax and pass the two dates(Start and End). And its format will start with a special character (#), it's code will go like this:-
SELECT * FROM sell
WHERE sellDate BETWEEN #10/07/2014# AND #12/02/2015#;