I have a simple table containing sample data like so:
I'm trying to run a query where if there are multiple of the same Color, pick the record that has the highest Purity value, but ONLY if there doesn't exist a record that contains a Purity = No Value.
For example, in the above, I would like to return the record:
Here's my SQL:
But what I'm getting is:
If I have the following table with no No Value:
Then I get the correct return Query record:
The data type of Purity is a Short Text. How can I set the query to return the record if there is a 'No Value' Purity, otherwise return the record with the highest value?
Color | Purity |
---|---|
Red | 10 |
Red | 3 |
Red | 9 |
Red | No Value |
Red | 12 |
Red | 11 |
I'm trying to run a query where if there are multiple of the same Color, pick the record that has the highest Purity value, but ONLY if there doesn't exist a record that contains a Purity = No Value.
For example, in the above, I would like to return the record:
Color | Purity |
---|---|
Red | No Value |
Here's my SQL:
Code:
SELECT TOP 1 Color, Purity
FROM Table1
WHERE Purity <> 'No Value' AND Color = [Table1].[Color]
ORDER BY CInt(IIF(Purity='No Value','No Value',Purity)) DESC;
But what I'm getting is:
If I have the following table with no No Value:
Color | Purity |
---|---|
Red | 10 |
Red | 3 |
Red | 9 |
Red | 12 |
Red | 11 |
Then I get the correct return Query record:
Color | Purity |
---|---|
Red | 12 |
The data type of Purity is a Short Text. How can I set the query to return the record if there is a 'No Value' Purity, otherwise return the record with the highest value?
Last edited: