How can I use NOT BETWEEN in a query in Phalcon?

ALDEAL1993

I am making a query using NOT BETWEEN using Phalcon Query Language (PHQL), but it is not working the application hangs. Someone could give me an idea of ​​how I could do it. Thank you very much. There is my query.

       $sql = "SELECT c.* FROM table as c 
      WHERE not exists c.activated NOT BETWEEN :f1: and :f2: ";
        $parameters['f1'] = '2017-10-01';
        $parameters['f2'] = '2017-10-05';
        $result= $this->modelsManager->executeQuery($sql, 
        $parameters);

every time the query is run this leaves:

Warning: session_destroy(): Trying to destroy uninitialized session in C:\xampp\htdocs\myapp\app\plugins\SecurityPlugin.php on line 222

Used_By_Already

I have never heard of Phalcon Query Language (PHQL) until I opened this question, but the syntax you are attempting isn't valid in SQL. Try this instead:

$sql = "SELECT c.* FROM table as c WHERE NOT c.activated BETWEEN :f1: and :f2: ";
    $parameters['f1'] = '2017-10-01';
    $parameters['f2'] = '2017-10-05';
    $result= $this->modelsManager->executeQuery($sql, 
    $parameters);

NOT ( your_predicate_here )

All you need is the NOT to reverse the true/false values being returned by the predicate. e.g. if a date IS between the dates (true), reverse that to false so it is equivalent to "not between".

SQL Fiddle

MySQL 5.6 Schema Setup:

CREATE TABLE Table1
    (`activated` datetime)
;

INSERT INTO Table1
    (`activated`)
VALUES
    ('2016-12-01 00:00:00'),
    ('2017-10-01 00:00:00'),
    ('2017-10-05 00:00:00')
;

Query 1:

SELECT c.* 
FROM table1 as c 
WHERE NOT c.activated BETWEEN '2017-10-01' AND '2017-10-05'

Results:

|            activated |
|----------------------|
| 2016-12-01T00:00:00Z |

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I count the numbers of rows that a phalcon query returned?

How can I count columns in phalcon volt?

How can I use 'AS' in my count query?

How can I use a variable in a query selector?

How can I use in query in mongodb?

powershell query - how many OR can i use?

How can I use if in SQL query

How can I use "+" in query string

How can i use data in an array in a query

How i can use result of subquery in this query?

How can I use this complete query with sequelizejs

How can I use my SQL query in the cursor query?

How can I use the result of a SQL query in another SQL query

How can I use a query result as a column for a separate query?

How can I use a SQL query result as a column in another query?

How can i use kibana visualization query in elasticsearch dsl query?

How can I access Phalcon configuration data in an external library?

How can i optimize this mysql query ? i use IN() operator

how to optimize mysql query in phalcon

Can I use Mutators in Query?

How can I use a media query in ng-style

How can I use a csv list for an SQL SELECT query?

How can I use unique query for every client connected to websocket

How can I use a parameterized query to search on a column by its name?

How can I use media query with emotion/styled/macro?

How can I make a query force to use such an index?

How can i use case alias in a select query

How can I use parameter's method in @Query annotation

How can I use a method withing a linq query?

How can I use the Like Operator with a Parameter in a SQLite query?