Retrieve NOT NULL value : Null « Data Type « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Data Type » Null 
Retrieve NOT NULL value
   
/*
mysql> select * from employee_person;
+----+-------------------------------------+---------+---------------------------+------------+------+----------+-----------------+----------+
| id | address                             | phone   | email | birthday   | sex  | m_status | s_name          | children |
+----+-------------------------------------+---------+---------------------------+------------+------+----------+-----------------+----------+
|  1 | 200, Regina Street                  | 7176666 | net@hotmail.com | 1971-04-26 | M    | Y        | Ane Regina      |     NULL |
|  2 | 1232 Alberta Road                   | 5553312 | jo@hotmail.com | 1968-03-02 | M    | Y        | Jane Van        |        3 |
|  3 | 90 Potter A                         | 3331211 | gp@ymail.com | 1967-09-22 | M    | N        | Sandhya Pil     |        2 |
|  4 | 202, Donna Street                   | 7176167 | twink@hotmail.com | 1976-08-09 | F    | Y        | Manish Sha      |     NULL |
|  5 | Apartment #8, UBC, Van Street       | 8973242 | holy@ymail.com| 1974-10-14 | F    | N        | NULL            |     NULL |
|  6 | 46 SFU Street                       | 6451234 | kill@el.com | 1978-12-31 | M    | N        | NULL            |     NULL |
|  7 | 432 Mercury Ave                     | 7932232 | mac@hotmail.com | 1966-08-21 | M    | Y        | Mary Shelly     |        3 |
|  8 | 8 Little YaleTown                   | 5442994 | edd@gmail.com | 1975-01-14 | M    | N        | NULL            |     NULL |
|  9 | 64 Temp Road                        | 4327652 | nan@pmail.com | 1969-05-19 | M    | Y        | Man Nanda       |        1 |
| 10 | 132 Metro House, Henry Street       | 5552376 | ra@hotmail.com | 1968-07-06 | M    | N        | NULL            |     NULL |
| 11 | 1 Grace Town, Van Avenue            | 5433879 | soundofsilence@boxer.net | 1957-11-04 | M    | Y        | Muriel Lovelace |        4 |
| 12 | 97 Oakland Road                     | 5423311 | kingarthur@roundtable.org | 1968-02-15 | M    | Y        | Rina Brighton   |        3 |
| 13 | 543 Applegate Lane                  | 3434343 | levy@cmail.com | 1968-09-03 | F    | Y        | Matt Shi        |        2 |
| 14 | 76 Fish Street                      | 7432433 | tink@email.com | 1965-04-28 | M    | N        | NULL            |     NULL |
| 15 | 98 Gun Street                       | 6500787 | danny@fhardy.com | 1966-06-23 | M    | Y        | Betty Cudly     |        3 |
| 16 | #5 Winnepag Homes                   | 5433243 | mike@cmail.com | 1964-03-06 | M    | Y        | Stella Stevens  |        2 |
| 17 | 652 Devon Building, 6th Jade Avenue | 5537885 | mona@darling.com | 1970-04-18 | F    | Y        | Edgar Alan      |        1 |
| 18 | Apartment #9, Together Towers       | 5476565 | odessey@hotmail.com | 1973-10-09 | M    | N        | NULL            |     NULL |
| 19 | Apartment #9, West Towers           | 5476565 | jire@hotmail.com | 1973-01-20 | M    | N        | NULL            |     NULL |
| 20 | 90 Yale Town                        | 7528326 | help@more.org | 1968-01-25 | F    | N        | NULL            |     NULL |
| 21 | 4329 Eucalyptus Avenue              | 4254863 | money@cold.com | 1964-06-13 | M    | Y        | Ruby Richer     |        2 |
+----+-------------------------------------+---------+---------------------------+------------+------+----------+-----------------+----------+
21 rows in set (0.02 sec)

mysql> select id, s_name from employee_person where s_name IS NOT NULL;
+----+-----------------+
| id | s_name          |
+----+-----------------+
|  1 | Ane Regina      |
|  2 | Jane Van        |
|  3 | Sandhya Pil     |
|  4 | Manish Sha      |
|  7 | Mary Shelly     |
|  9 | Man Nanda       |
| 11 | Muriel Lovelace |
| 12 | Rina Brighton   |
| 13 | Matt Shi        |
| 15 | Betty Cudly     |
| 16 | Stella Stevens  |
| 17 | Edgar Alan      |
| 21 | Ruby Richer     |
+----+-----------------+
13 rows in set (0.00 sec)


*/       
Drop table employee_person;

CREATE TABLE employee_person (
    id int unsigned not null primary key, 
    address varchar(60)
    phone int, 
    email varchar(60)
    birthday DATE, 
    sex ENUM('M''F')
    m_status ENUM('Y','N')
    s_name varchar(40)
    children int
);


INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_namevalues (1'200, Regina Street', 7176666'net@hotmail.com', '1971-04-26', 'M''Y''Ane Regina');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (2'1232 Alberta Road', 5553312'jo@hotmail.com', '1968-03-02', 'M''Y''Jane Van', 3);
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (3'90 Potter A', 3331211'gp@ymail.com', '1967-09-22', 'M''N''Sandhya Pil', 2);
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_namevalues (4'202, Donna Street', 7176167'twink@hotmail.com', '1976-08-09', 'F''Y''Manish Sha');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (5'Apartment #8, UBC, Van Street', 8973242'holy@ymail.com', '1974-10-14', 'F''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (6'46 SFU Street', '6451234', 'kill@el.com', '1978-12-31', 'M''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (7'43Mercury Ave', 7932232'mac@hotmail.com', '1966-8-21', 'M''Y''Mary Shelly', '3');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (8'8 Little YaleTown', 5442994'edd@gmail.com', '1975-01-14', 'M''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (9'64 Temp Road', 4327652'nan@pmail.com', '1969-05-19', 'M''Y''Man Nanda', '1');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (10'13Metro House, Henry Street', 5552376'ra@hotmail.com', '1968-07-06', 'M''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (11'1 Grace Town, Van Avenue', 5433879'soundofsilence@boxer.net', '1957-11-04', 'M''Y''Muriel Lovelace', '4');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (12'97 Oakland Road', 5423311'kingarthur@roundtable.org', '1968-02-15', 'M''Y''Rina Brighton', 3);
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (13'54Applegate Lane', 3434343'levy@cmail.com', '1968-09-03', 'F''Y''Matt Shi', '2');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (14'76 Fish Street', 7432433'tink@email.com', '1965-04-28', 'M''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (15'98 Gun Street', 6500787'danny@fhardy.com', '1966-06-23', 'M''Y''Betty Cudly', 3);
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (16'#5 Winnepag Homes', 5433243'mike@cmail.com', '1964-03-06', 'M''Y''Stella Stevens', 2);
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (17'65Devon Building, 6th Jade Avenue', 5537885'mona@darling.com', '1970-04-18', 'F''Y''Edgar Alan', 1);
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (18'Apartment #9, Together Towers', 5476565'odessey@hotmail.com', '1973-10-09', 'M''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (19'Apartment #9, West Towers', 5476565'jire@hotmail.com', '1973-1-20', 'M''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_statusvalues (20'90 Yale Town', 7528326'help@more.org', '1968-01-25', 'F''N');
INSERT INTO employee_person (id, address, phone, email, birthday, sex, m_status, s_name, childrenvalues (21'4329 Eucalyptus Avenue', 4254863'money@cold.com', '1964-06-13', 'M''Y''Ruby Richer', 2);
  
  
  
select from employee_person;  
  
select id, s_name from employee_person where s_name IS NOT NULL;
    


           
         
    
    
  
Related examples in the same category
1.Retrieve NULL value
2.Concatenate string with NULL value
3.Working with NULL Values
4.Use the IS NULL and IS NOT NULL operators
5.NULL means 'not having a value'
6.Disallowing NULLs
7.List NOT NULL value and order it
8.Select NOT NULL value
9.IS NOT NULL in where clause
10.NULL value in where clause
11.Read NULL value
12.Dealing With NULL Data
13.An important one to note; the result is not 0 (false), it's NULL
14.To evaluate NULL rows
15.NULL is basically a third possible result of an evaluation: There's true, false, and then there's NULL.
16.Use the IS NULL (or IS NOT NULL) comparison instead
17.Assuming that NULL values sort ahead of all non-NULL values
18.Passing a NULL value to a function results in a NULL return value.
19.Set value to null
20.What is the result of the calculation 10 divided by 0?
21.If the value of an expression cannot be determined, the result is NULL:
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.