Get highest value from column in where clause

Ted

I have table:

id date  day
2  21-07 1
2  10-07 3
2  11-07 2

I need to get date which has highest day, in current example it should be 10-07. Next query works fine, but is there way to make it more optimised?

SELECT date
      FROM (SELECT date, MAX(day)
            FROM some_table 
            WHERE id = 2
            GROUP BY date
        LIMIT 1) x
Gordon Linoff

I would not suggest a where clause. Just use:

select date
from some_table
where id = 2
order by day desc
limit 1;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get the highest id from a specific where clause

Get max/min value of the column independet from where clause

How to get the highest value from MySQL column

Get value from Database to Linq where clause

Sequeilize find highest value of table in where clause

SQL Get highest repeating value for a group clause

How to get second highest value from a column pyspark?

How to get a value of same column which is being search with where clause

How to get rows where a column has highest value and another column has a specific value in laravel query builder

Referancing value from select column in where clause : Oracle

Ignoring column with the highest value where substring matches

Where clause completed from a column

Where clause from array column

How to get a value from one pyspark dataframe using where clause

Get highest value from results

How do I get the value from 1 column based on highest value of another column of the same row?

Pandas: Get highest value from a column for each unique value in another column

pandas: get column and row name where row has the highest value for every row

Rank value from a column from lowest to highest

mysql get highest value with column name

Laravel get highest value of each column

PHP: get the highest and lowest value in a mysql column?

Select highest value from a column SQL

Getting highest column value from joined table

Exclude column in where clause if field value is empty

Add a Max value calculated column to a Where clause?

Return column value based on results of WHERE clause

WHERE clause operator based on column value

Is there a way to extract a column value and use it in a where clause?