Question: I am trying to fetch the record as per multiple IDS and calculate the min value using PHP and MySQL. I am explaining the query below.

```
SELECT MIN(min_price) AS base_price,entity_id 
FROM catalog_product_index_price 
WHERE entity_id IN
    ('31439,31440,31441,31442,31443,31444,31445,31446,31447,31448,31469,31470,31471,
31472,31473')

```

Here I am trying to calculate the min value of `min_price` column as per these multiple `entity_id`. But in my case some of the `entity_id` like `31439,31440,31441` dont have any records present inside `catalog_product_index_price` table so the final result is coming as `NULL` for both `base_price and entity_id`. I need to calculate the min price of those `entity_id` has the records only.

Answer: 
You can only count the columns that have a value.

Also if the entity\_id is a numeric field you need to remove the quotes.

For example:

```
SELECT MIN(min_price) AS base_price,entity_id 
FROM catalog_product_index_price 
WHERE entity_id IN (31439, 31440, 31441, 31442, 31443, 31444, 31445, 31446, 31447, 31448, 31469 ,31470, 31471, 31472, 31473)
AND min_price > 0;

```
```
SELECT MIN(min_price) AS base_price,entity_id 
FROM catalog_product_index_price 
WHERE entity_id IN
    ('31439,31440,31441,31442,31443,31444,31445,31446,31447,31448,31469,31470,31471,
31472,31473')
AND min_price is not null;

```