Jump to content

[SOLVED] How do I select only fields that have data?


gnawz

Recommended Posts

Hi,

 

Any one know how to write a MySQL SQL that selects fields that are not blank based on a condition?

 

eg a database that has many columns that are all inserted into or updated at different times; meaning at some poit some fields are updated while others remain blank.

 

When I select, I only want to see fields that are not empty.

Alternatively u can use the following snippet to test for null values:

<?php
$results = mysql_query("SELECT name FROM users WHERE name IS NOT NULL");
?>

 

That would normally require to have that field set as NULL. If u havent (u should), then a simple string compare will do:

<?php
$results = mysql_query("SELECT name FROM users WHERE name != ''");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.