Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of "where in"

Tags:

mysql

i would like ask you if exist a command that do the opposite of WHERE IN, i want select all the row with different pamaters of an array.

<?php
 $data = array(1,2,3);
 // normal query
 $query = "SELECT * FROM table_1 WHERE id <> 1 && id <> 2 && id <> 3";
 // how can i do the same query passing an array?

?>
like image 368
Fabrizio Fenoglio Avatar asked Jan 26 '26 06:01

Fabrizio Fenoglio


1 Answers

You can always use NOT before any validation in SQL to get the opposite of it.

In your case it would be:

SELECT * 
FROM table_1 
WHERE id NOT IN (1,2,3);
like image 56
Filipe Silva Avatar answered Jan 28 '26 00:01

Filipe Silva