XIMRX
XIMRX

Reputation: 2172

MySQL select the largest value along with greater-than clause?

How to select only one row that has highest value in colum1, also making sure that the selected colum1 value is greater-than n

SELECT * FROM thetable WHERE colum1 >= 150 ORDER BY amount LIMIT 1
//using limit to get 1 row
//using where to fulfill greathe-than criteria
//using order by to sort and get max one.

The above query is giving greater-than 150 row but not the maximum one of table, what is wrong in query?

Upvotes: 1

Views: 1833

Answers (1)

CodingYoshi
CodingYoshi

Reputation: 27019

You need to use max and having like this hypothetical query. Here we are getting the country with the highest number of branches which has more than 7 branches (8 or more):

SELECT country,MAX(no_of_branch)
FROM publisher
GROUP BY country
HAVING MAX(no_of_branch)>=8;

More here

Upvotes: 3

Related Questions