Skip to content

Commit 382c5da

Browse files
committedMar 7, 2024
NULL values
1 parent 2e3ce12 commit 382c5da

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
 

‎database-queries/MYSQL/NULL/Readme.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SQL NULL Values
2+
- A field with a `NULL` value is a field with no value.
3+
- If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a `NULL` value.
4+
- It is not possible to test for NULL values with comparison operators, such as =, <, or <>.
5+
- We will have to use the `IS NULL` and IS `NOT NULL` operators instead.
6+
7+
**IS NULL Syntax**:
8+
9+
SELECT column_names
10+
FROM table_name
11+
WHERE column_name IS NULL;
12+
13+
14+
**IS NOT NULL Syntax**:
15+
16+
SELECT column_names
17+
FROM table_name
18+
WHERE column_name IS NOT NULL;
19+
20+
21+
## CUSTOMERS
22+
23+
| CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
24+
|------------|--------------------|-----------------|--------------------|------------|------------|---------|
25+
| 1 | Company A | John Doe | 123 Main Street | New York | 10001 | USA |
26+
| 2 | Company B | Jane Smith | 456 Oak Avenue | Los Angeles| 90001 | USA |
27+
| 3 | Company C | Michael Johnson | 789 Elm Drive | Chicago | 60601 | USA |
28+
| 4 | Company D | Sarah Brown | 101 Pine Road | Houston | 77001 | USA |
29+
| 5 | Company E | Sarah Jaden | | barcelona | 77031 | SPAIN |
30+
31+
32+
### Q1
33+
From the `CUSTOMERS` Table, lists all customers with a NULL value in the "Address" field.
34+
35+
```sql
36+
SELECT * FROM CUSTOMERS WHERE Address IS NULL;
37+
```
38+
39+
### Q2
40+
From the `CUSTOMERS` Table, lists all customers with a value in the "Address" field:
41+
42+
```sql
43+
SELECT * FROM CUSTOMERS WHERE Address IS NOT NULL;
44+
```

0 commit comments

Comments
 (0)
Please sign in to comment.