catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

how handle "NOT" operation in where clause #718

Closed HASSANDL closed 6 years ago

HASSANDL commented 6 years ago

Hello. I want using "OR NOT" in sql. example:

SELECT * FROM users
WHERE id > 2 OR NOT (
    name LIKE '%sd' AND name LIKE '%sassd'
)

how handle in where clause Medoo? thanks.

catfan commented 6 years ago

Why don't just use [!~] for NOT LIKE?

https://medoo.in/api/where (LIKE Condition section)

$database->select('users', '*', [
    'OR' => [
        'id[>]' => 2,
        'AND' => [
            'name[!~]' => ['AND' => ['%sd', '%sassd']]
        ]
    ]
]);

The output:

SELECT * FROM `users` WHERE (`id` > 2 OR ((`name` NOT LIKE '%sd' AND `name` NOT LIKE '%sassd')))
HASSANDL commented 6 years ago

how handle this (NOT OR)?

$database->select('users', '*', [
    'NOT OR' => [
        'id[>]' => 2,
        'AND' => [
            'name' => ['AND' => ['%sd', '%sassd']]
        ]
    ]
]);
catfan commented 6 years ago

There is no NOT OR.