0

I have a mysql table, which is as follows:

 image_id   imagename   brandname    x       y    
    143     00003.jpg     Pirelli  147      265
    125     00003.jpg     Pirelli  500      259

Through mouse clicks I am generating x and y positions on a html canvas which I want to use to subset the table. For example, if the clicked position of x and y were 510 and 262, I want to retrieve the image id 125 as both the parameters are matching.

Suppose if the x value generated with mouse click is 510, i want to select the line with image_id 125.

I tried the following:

select * from table where imagename='00003.jpg' and 510 < max(x);

I am getting this error:

invalid use of group function.

1

4 Answers 4

1

Max is a group function... You can't use it without having group by in it.

You are comparing X and y value so use them directly, no need for using Max

Sign up to request clarification or add additional context in comments.

Comments

0

As @user769889 already mentioned, you can't use aggregate functions like Min, Max etc without using Group By that's why you are getting that error.

I think you need this :

select * from table where imagename='00003.jpg' and x < 510 and y < 262

Comments

0

Max is a grouping function, you cannot use it like that. You can achieve what you need by using the followind nested query:

select * from table where imagename='00003.jpg' and 510 < (select max(x) from table where imagename = '00003.jpg')

This will run the inner query that gives back the maximum value for the x column for the image, then runs the outer query using the result in its where clause!

1 Comment

I am getting both the rows returned...instead I have to retrieve only the second line in the table....whereas to test if max(x) condition is working, when I ran the max(x) part of the code separately, it fetches correct result.
0

This is what worked for me:

select * from annotations where imagename='00003.jpg' x <= 510 order by x desc limit 1;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.