Medoo icon indicating copy to clipboard operation
Medoo copied to clipboard

Add IN and NOT IN in WHERE clause

Open Vendict opened this issue 4 years ago • 6 comments

But on right side use only RAW.

Vendict avatar Aug 21 '21 16:08 Vendict

There is it

https://github.com/catfan/Medoo/blob/master/src/Medoo.php#L903 https://github.com/catfan/Medoo/blob/master/src/Medoo.php#L989

catfan avatar Aug 22 '21 05:08 catfan

But your solution don't solve like this select * from table1 where id not in (select id2 from table2)

Vendict avatar Aug 22 '21 05:08 Vendict

My solution can also solve your problem, and it is more

https://github.com/catfan/Medoo/pull/1003

$this->database->select( "account", "user_name", [ Medoo::raw(" not in (select id2 from table2) "), 'LIMIT' => [20, 100], "ORDER" => "user_id", ] );

phpseven avatar Aug 23 '21 03:08 phpseven

My solution can also solve your problem, and it is more

[
Medoo::raw(" not in (select id2 from table2) "),

need key on first row of this array: PHP Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, object given in Medoo.php:859 You tested this ?

Please correct me, but on this :

$a = $database->select("company", '*', [
        'ID'=> Medoo::raw(" not in (select company_id from table2)"),
    ]);

I recive this SQL:

SELECT * FROM "company" WHERE "ID" = not in (select company_id from table2)

Vendict avatar Aug 23 '21 05:08 Vendict

My solution can also solve your problem, and it is more

[
Medoo::raw(" not in (select id2 from table2) "),

need key on first row of this array: PHP Fatal error: Uncaught TypeError: preg_match() expects parameter 2 to be string, object given in Medoo.php:859 You tested this ?

Please correct me, but on this :

$a = $database->select("company", '*', [
        'ID'=> Medoo::raw(" not in (select company_id from table2)"),
    ]);

I recive this SQL:

SELECT * FROM "company" WHERE "ID" = not in (select company_id from table2)

Use the master branch in my repository to modify, and you have to write this

$a = $database->select("company", '*', [ Medoo::raw("<ID> not in (select company_id from table2)"), ]);

phpseven avatar Aug 23 '21 05:08 phpseven

Use the master branch in my repository to modify, and you have to write this

thank you, I already used my solution in small project and try to share to another people to help

Vendict avatar Aug 23 '21 05:08 Vendict