logo
down
shadow

SQL WHERE IS NOT NULL still returns null rows


SQL WHERE IS NOT NULL still returns null rows

By : user2185439
Date : November 21 2020, 04:01 AM
like below fixes the issue I have a query where I select all records if they are not NULL but I still get results with NULL rows in it. , Presumably, you want a query like this:
code :
SELECT cnt.id, cnt.title as content_title, cnt.alias as content_alias, cnt.images, cnt.introtext, cnt.catid, cat.title as cat_title, cat.alias as cat_alias,
       MAX(case when f.field_id = 2 then f.value end) as regio
FROM snm_content cnt LEFT JOIN
     snm_categories cat
     ON cat.id = cnt.catid LEFT JOIN
     snm_fields_values f
     ON cnt.id = f.item_id AND f.value LIKE '%Zeeland%'
WHERE cnt.id IS NOT NULL
GROUP BY cnt.id;


Share : facebook icon twitter icon
managedQuery(Media.EXTERNAL_CONTENT_URI, projection,null,null, null); returns null when running on device

managedQuery(Media.EXTERNAL_CONTENT_URI, projection,null,null, null); returns null when running on device


By : fluxus2x
Date : March 29 2020, 07:55 AM
Hope that helps , same for this code working
code :
public class LoadImagesFromSDCardActivity extends Activity implements
OnItemClickListener {

/**
 * Grid view holding the images.
 **/

private GridView sdcardImages;
/**
 * Image adapter for the grid view.
 **/
private ImageAdapter imageAdapter;
/**
 * Display used for getting the width of the screen. 
 **/
private Display display;
ImageView imgView;

/**
 * Creates the content view, sets up the grid, the adapter, and the click listener.
 * 
 * @see android.app.Activity#onCreate(android.os.Bundle)
 **/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    // Request progress bar
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.main);

    display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    imgView=(ImageView)findViewById(R.id.imgView);
    setupViews();
    setProgressBarIndeterminateVisibility(true); 
    loadImages();
}

/**
 * Free up bitmap related resources.
 **/
protected void onDestroy() {
    super.onDestroy();
    final GridView grid = sdcardImages;
    final int count = grid.getChildCount();
    ImageView v = null;
    for (int i = 0; i < count; i++) {
        v = (ImageView) grid.getChildAt(i);
        ((BitmapDrawable) v.getDrawable()).setCallback(null);
    }
}
/**
 * Setup the grid view.
 **/
private void setupViews() {
    sdcardImages = (GridView) findViewById(R.id.sdcard);
    sdcardImages.setNumColumns(display.getWidth()/95);
    sdcardImages.setClipToPadding(false);
    sdcardImages.setOnItemClickListener(LoadImagesFromSDCardActivity.this);
    imageAdapter = new ImageAdapter(getApplicationContext()); 
    sdcardImages.setAdapter(imageAdapter);
}
/**
 * Load images.
 */
private void loadImages() {
    final Object data = getLastNonConfigurationInstance();
    if (data == null) {
        new LoadImagesFromSDCard().execute();
    } else {
        final LoadedImage[] photos = (LoadedImage[]) data;
        if (photos.length == 0) {
            new LoadImagesFromSDCard().execute();
        }
        for (LoadedImage photo : photos) {
            addImage(photo);
        }
    }
}
/**
 * Add image(s) to the grid view adapter.
 * 
 * @param value Array of LoadedImages references
 */
private void addImage(LoadedImage... value) {
    for (LoadedImage image : value) {
        imageAdapter.addPhoto(image);
        imageAdapter.notifyDataSetChanged();
    }
}

/**
 * Save bitmap images into a list and return that list. 
 * 
 * @see android.app.Activity#onRetainNonConfigurationInstance()
 */
@Override
public Object onRetainNonConfigurationInstance() {
    final GridView grid = sdcardImages;
    final int count = grid.getChildCount();
    final LoadedImage[] list = new LoadedImage[count];

    for (int i = 0; i < count; i++) {
        final ImageView v = (ImageView) grid.getChildAt(i);
        list[i] = new LoadedImage(((BitmapDrawable) v.getDrawable()).getBitmap());
    }

    return list;
}
/**
 * Async task for loading the images from the SD card. 
 * 
 * @author Mihai Fonoage
 *
 */
class LoadImagesFromSDCard extends AsyncTask<Object, LoadedImage, Object> {

    /**
     * Load images from SD Card in the background, and display each image on the screen. 
     *  
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
    @Override
    protected Object doInBackground(Object... params) {
        //setProgressBarIndeterminateVisibility(true); 
        Bitmap bitmap = null;
        Bitmap newBitmap = null;
        Uri uri = null;            

        // Set up an array of the Thumbnail Image ID column we want
        String[] projection = {MediaStore.Images.Thumbnails._ID};
        // Create the cursor pointing to the SDCard
        Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                projection, // Which columns to return
                null,       // Return all rows
                null,       
                null); 
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
        int size = cursor.getCount();
        // If size is 0, there are no images on the SD Card.
        if (size == 0) {
            //No Images available, post some message to the user
        }
        int imageID = 0;
        for (int i = 0; i < size; i++) {
            cursor.moveToPosition(i);
            imageID = cursor.getInt(columnIndex);
            uri = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, "" + imageID);
            try {
                bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
                if (bitmap != null) {
                    newBitmap = Bitmap.createScaledBitmap(bitmap, 70, 70, true);
                    bitmap.recycle();
                    if (newBitmap != null) {
                        publishProgress(new LoadedImage(newBitmap));
                    }
                }
            } catch (IOException e) {
                //Error fetching image, try to recover
            }
        }
        cursor.close();
        return null;
    }
    /**
     * Add a new LoadedImage in the images grid.
     *
     * @param value The image.
     */
    @Override
    public void onProgressUpdate(LoadedImage... value) {
        addImage(value);
    }
    /**
     * Set the visibility of the progress bar to false.
     * 
     * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
     */
    @Override
    protected void onPostExecute(Object result) {
        setProgressBarIndeterminateVisibility(false);
    }
}

/**
 * Adapter for our image files. 
 * 
 * @author Mihai Fonoage
 *
 */
class ImageAdapter extends BaseAdapter {

    private Context mContext; 
    private ArrayList<LoadedImage> photos = new ArrayList<LoadedImage>();

    public ImageAdapter(Context context) { 
        mContext = context; 
    } 

    public void addPhoto(LoadedImage photo) { 
        photos.add(photo); 
    } 

    public int getCount() { 
        return photos.size(); 
    } 

    public Object getItem(int position) { 
        return photos.get(position); 
    } 

    public long getItemId(int position) { 
        return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
        final ImageView imageView; 
        if (convertView == null) { 
            imageView = new ImageView(mContext); 
        } else { 
            imageView = (ImageView) convertView; 
        } 
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setPadding(8, 8, 8, 8);
        imageView.setImageBitmap(photos.get(position).getBitmap());
        return imageView; 
    } 
}

/**
 * A LoadedImage contains the Bitmap loaded for the image.
 */
private static class LoadedImage {
    Bitmap mBitmap;

    LoadedImage(Bitmap bitmap) {
        mBitmap = bitmap;
    }

    public Bitmap getBitmap() {
        return mBitmap;
    }
}
/**
 * When an image is clicked, load that image as a puzzle. 
 */
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {        
    int columnIndex = 0;
    String[] projection = {MediaStore.Images.Media.DATA};
    Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            projection,
            null, 
            null, 
            null);
    if (cursor != null) {
        columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToPosition(position);
        String imagePath = cursor.getString(columnIndex); 

        FileInputStream is = null;
        BufferedInputStream bis = null;
        try {
            is = new FileInputStream(new File(imagePath));
            bis = new BufferedInputStream(is);
            Bitmap bitmap = BitmapFactory.decodeStream(bis);
            Bitmap useThisBitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
            Log.i("called","called");
            imgView.setImageBitmap(useThisBitmap);
            bitmap.recycle();
            //Display bitmap (useThisBitmap)
        } 
        catch (Exception e) {
            //Try to recover
        }
        finally {
            try {
                if (bis != null) {
                    bis.close();
                }
                if (is != null) {
                    is.close();
                }
                cursor.close();
                projection = null;
            } catch (Exception e) {
            }
        }
    }
  }

}
  <GridView  
    android:id="@+id/sdcard"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp" 
    android:stretchMode="columnWidth"
    android:gravity="center" />
    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imgView"
    ></ImageView>
</LinearLayout>  
SQL where IS NULL returns rows where data is NOT NULL

SQL where IS NULL returns rows where data is NOT NULL


By : Todd
Date : March 29 2020, 07:55 AM
I hope this helps you . As other told you, you have to use parenthesis around the OR condition.
Why ? Because the OR has a lower priority than AND
code :
 SELECT id, 
        name, 
        whitepaper, 
        date_start, 
        date_end  FROM approved  
 WHERE   date_start >= CURDATE() 
         OR
         ( 
           date_end >= CURDATE() 
           AND
           whitepaper IS NULL
         )
         ORDER BY date_end DESC  LIMIT 10
Printing contents of array just returns [null, null, null, null]

Printing contents of array just returns [null, null, null, null]


By : user3209108
Date : March 29 2020, 07:55 AM
To fix this issue , Change the first line of your main() method to:
code :
    PresidentNames =  new String[] {"George Bush", "William J. Clinton", "George W. Bush", "Barrack H. Obama", "Donald J. Trump"};
IS NOT NULL returns all rows including column with NULL

IS NOT NULL returns all rows including column with NULL


By : ajie
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have a database which has multiple columns, but I am ONLY INTERESTED to get two columns col-A & col-B, with the condition that the row will have: col-A be any value & col-B must be NOT NULL. , Check for both conditions: Blank and null
Why does null||null return a null value but concat(null,null) returns an empty string in postgres?

Why does null||null return a null value but concat(null,null) returns an empty string in postgres?


By : Rima
Date : March 29 2020, 07:55 AM
hop of those help? I'm trying to understand the differences between concat() and || in postgres when using nulls. Why does concat() return an empty string if both sides of the concat are null? , in concat() function:
code :
text concat(str "any",...)  Concatenate all arguments. NULL arguments are ignored.
Related Posts Related Posts :
  • MySQL error: "NUMBER" is not valid at this position, expecting: BIT, BOOL, BOOLEAN, DATE, TIME, ENUM
  • months between initial and final month
  • SQL how to subtract result row 1 from row 2, row 2 from row 3
  • How to fill third column in mySQL table?
  • Inner Join 2 tables multiple result
  • MySQL find the top 2 busiest shipment lines with source_port and destination_port switchable
  • How to return a value like '0' when using count case and the column is null?
  • MySql query code to fetch unique data from single ID
  • Should procedure return value?
  • Trigger with query data
  • How to make simple SQL request in mySQL?
  • Trigger INSERT SQL multiple data
  • MySQL insert ignore for duplicates but fail on foreign key errors
  • SQL Many to Many JSON
  • Add foreign key in Rails
  • How to check a string has value in MySQL
  • How to implement multiple Google Cloud Functions with Cloud SQL?
  • SQL recursive query (MySQL 5.7)
  • Single row result of join sql query
  • SQL - Group by certain field and concat another
  • Generate anonymous ids in JOIN query
  • how to order by month name chronologically instead of alphabetically?
  • How to find unique column which has wrong entry with other column MYSQL
  • MySQL query help require
  • STR_TO_DATE to replace non english month names
  • SQL - Create trigger after insert
  • SQL Replace Join With Something Faster
  • how to copy one column to another with data in mysql on same table?
  • How to write the query without using sub query?
  • mysql join only if a field has a particular value
  • "Call to undefined method Illuminate\Support\Facades\File::save()"
  • Select top 3 values from a table in MySQL
  • MySql returns wrong time from table data
  • Running a "Select * From tableName" query using MySQL/OTP, with no 'WHERE'
  • What's the mysql's \G equivalent for firebird database?
  • Mysql full text returnig NULL
  • What is this bash script trying to do with mysql?
  • Setting up Django with MySQL on macOS
  • Reduce memory usage in Google Cloud SQL
  • MySQL: refind groups of user from group description
  • How to identify and delete or update duplicate rows in Mysql table
  • MySQL handle unicode text for utf8mb4_unicode_ci
  • making an eloquent relation for users that follow each other
  • mySQL ORDER based on multiple criteria
  • multiple inner joins adds extra values to count
  • How do add together a COUNT() using SUM()?
  • Count elements from a table with differents conditions in mySql?
  • Updating multiple rows using WHERE... IN
  • Optimize SQL result to ScreenWriter
  • query to return single field from spring data mongo
  • Get column content from one table and use it to get id from other table
  • SQL Query to get users and orders data
  • Query: Count how many times a parameter in one table does not exist in another
  • How to join a table multiple times?
  • I have 2 queries with only one difference that I want to merge in just one query
  • Substring after last dot
  • Isolate the Count that comes from a LEFT JOIN independent of the WHERE clause filters
  • How to load Dynamic XML data in table
  • SQL - Hard time building a "complex" request
  • Difference between EXISTS and JOIN to check existence of records
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org