Jump to content

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


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 != ''");
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.