gnawz Posted August 15, 2008 Share Posted August 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/119844-solved-how-do-i-select-only-fields-that-have-data/ Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Fields that are empty should be NULL Then you can include WHERE !ISNULL(field) in your query Quote Link to comment https://forums.phpfreaks.com/topic/119844-solved-how-do-i-select-only-fields-that-have-data/#findComment-617404 Share on other sites More sharing options...
Fadion Posted August 16, 2008 Share Posted August 16, 2008 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 != ''"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/119844-solved-how-do-i-select-only-fields-that-have-data/#findComment-617727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.