Select all but some lines

let's say I have a table with this structure:

id model color ------ -------- ---------- 1 Ford yellow 2 Ford green 3 Ford red 4 Ford yellow 5 Subaru yellow 6 Subaru red 

I need to make a request that returns me every car in the list, except ford's yellow. Can anyone help?

+5
source share
5 answers
 ... WHERE NOT (model = 'Ford' AND color = 'yellow') 
+13
source

If you want to deselect some rows dynamically, you can use it:

 SELECT * FROM `table_1` WHERE id NOT IN (SELECT id FROM `table_2` WHERE column_name='value') 

NOTE. Here id is the column_name that has both tables.

Good luck. :)

+4
source

In addition to Foo Bah's answer,

if you have null column values ​​such as:

 NAME COLOR Ford green Ford red Subaru yellow Subaru red Subaru NULL Ford NULL 

you need to use the ISNULL () function to output the values ​​of the null column

 ... WHERE NOT (ISNULL(NAME,'') = 'Ford' AND ISNULL(COLOR,'') = 'yellow') 
+1
source

Use the color <> "yellow" and the model <> "Ford" as a where clause

0
source

Hope this helps you.

  $this->db->where('model !=','FORD' AND 'color!=','yellow'); $query= $this->db->get('table_name'); $res = $query->result_array(); return $res; 
0
source

Source: https://habr.com/ru/post/1369072/


All Articles