Not equal in where : Where « Where Clause « SQL / MySQL






Not equal in where

   
/*
mysql> select * from Student;
+-----------+------------+-----------+
| StudentID | first_name | last_name |
+-----------+------------+-----------+
|         1 | John       | Jones     |
|         2 | Gary       | Burton    |
|         3 | Emily      | Scarlett  |
|         4 | Bruce      | Lee       |
|         5 | Anna       | Wolff     |
|         6 | Vic        | Andrews   |
|         7 | Steve      | Alaska    |
+-----------+------------+-----------+
7 rows in set (0.00 sec)

mysql> select * from Student WHERE first_name != "Bruce" AND last_name != "Jones
";
+-----------+------------+-----------+
| StudentID | first_name | last_name |
+-----------+------------+-----------+
|         2 | Gary       | Burton    |
|         3 | Emily      | Scarlett  |
|         5 | Anna       | Wolff     |
|         6 | Vic        | Andrews   |
|         7 | Steve      | Alaska    |
+-----------+------------+-----------+
5 rows in set (0.02 sec)


*/
Drop table Student;

CREATE TABLE Student (
   StudentID INT NOT NULL PRIMARY KEY,
   first_name      VARCHAR(50) NOT NULL,
   last_name      VARCHAR(50) NOT NULL
   
)TYPE = InnoDB;


INSERT INTO Student (StudentID,first_name, last_name) VALUES (4,'Bruce', 'Lee');

INSERT INTO Student (StudentID,first_name, last_name) VALUES (1,'John', 'Jones');
INSERT INTO Student (StudentID,first_name, last_name) VALUES (2,'Gary', 'Burton');
INSERT INTO Student (StudentID,first_name, last_name) VALUES (7,'Steve', 'Alaska');
INSERT INTO Student (StudentID,first_name, last_name) VALUES (5,'Anna', 'Wolff');
INSERT INTO Student (StudentID,first_name, last_name) VALUES (6,'Vic', 'Andrews');
INSERT INTO Student (StudentID,first_name, last_name) VALUES (3,'Emily', 'Scarlett');

select * from Student;
                                 
select * from Student WHERE first_name != "Bruce" AND last_name != "Jones";


           
         
    
    
  








Related examples in the same category

1.Getting the List of Products That Are on Catalog Promotion
2.Using Where Conditions
3.WHERE Clause Comparisons
4.Combining WHERE Conditions
5.Calculation in WHERE clause
6.Compare and calculate in Where clause
7.Do Calculation in Where and order
8.Where clause: nested conditions
9.Where clause: calculation and equal condition
10.Where clause: compare
11.Where clause: XOR
12.Use where clause the narrow down results
13.Use CURRENT_DATE in where clause
14.WHERE TRUE OR FALSE
15.Change localhost to the name of the machine where you'll be working.
16.WHERE clauses can test multiple conditions.
17.To put first those records where people sent messages to themselves
18.Using a WHERE clause that matches up values in the author ID column
19.Add a WHERE clause that looks for NULL values in the book column that is named in the ON clause
20.Add an expression to the WHERE clause that explicitly excludes the reference
21.Adds an additional condition to the WHERE clause and the calculated columns must have a total greater than 20
22.A WHERE clause that contains two expressions (conditions)
23.Searches for surnames that have an e anywhere in the name and then end with an e:
24.Show all records where the color is "Silver" and the price is above 100.00
25.Show records where make is "Krups", "Gaggia" or "DeLonghi" and the model is not "TSK-182" or "EC410"
26.Show all records where the color is not "Silver" or the price is below 100.00
27.Get the number of items for each color where the price exceeds 150.00 and when there is more than 1 item for t
28.Check day name in where clause
29.Compare the results from two statements