Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Null Values from MYSQL during select

Tags:

php

mysql

I have a survey form which records multiple responses in a MYSQL table and each member can refer to a different member in a different response or choose not to which will then be set as NULL as the table below.

membername-----referralto
Mike  -------- NULL
Ali  --------  NULL 
Mike  -------  Jack  
Ali  --------  Jill

I want the names of members and who the referrals were for. So here's what i tried;

SELECT membername, referralto 
FROM responses

This query returns me the NULL Values in the referralto fields as well. Is there a way i can filter out the NULL Values? I even tried this as well but it didn't work.

SELECT membername, NULLIF( referralto, '' )  AS member 
FROM responses

Thank you.

like image 737
Ahmad Avatar asked Jun 30 '26 15:06

Ahmad


1 Answers

Have you tried just adding "where referralto is not null"?

SELECT membername, NULLIF( referralto, '' )  AS member 
FROM responses
WHERE referralto IS NOT NULL
like image 130
Amarnasan Avatar answered Jul 03 '26 04:07

Amarnasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!