Site icon Health Post

Complex SQL join condition to Eliminate the NULL

CREATE TABLE EMP 
(
    E_ID INT,
    E_NAME VARCHAR(20),
    GENDER VARCHAR(20),
    CONTACT INT,
    AGE INT
);

INSERT INTO EMP 
VALUES (1001, 'ABC', 'MALE', NULL, NULL),
       (1001, 'ABC', NULL, 8989, NULL),
       (1001, 'ABC', NULL, NULL, 28);

I tried following query.. But not works..

SELECT 
    A.E_ID, B.E_NAME, B.GENDER, B.CONTACT, B.AGE 
FROM 
    EMP AS A 
INNER JOIN 
    ENT AS B ON A.E_ID = B.E_ID 
             AND A.E_NAME = B.E_NAME  
             AND A.GENDER = B.GENDER 
             AND A.CONTACT = A.CONTACT 
WHERE
    A.CONTACT IS NOT NULL;

Employee Table

How to get the single row output with not null values?

Expected Output

Exit mobile version