0

i have a table in mysql database. table 'sell_stats'

+-------------------+-----------+--------+
|  id   | max_price | sell_price| orders |
+-------------------+-----------+--------+
|  1    |   120     | 110       |  1     |
|  2    |   324     | 324       |  0     |
|  3    |   445     | 445       |  1     |
|  4    |   654     | 654       |  1     |
|  5    |   657     | 657       |  0     |
|  6    |   456     | 456       |  2     |
+-----------------+-------------+--------+

I want to find those columns in which max_price != sell_price

i wrote this query for that

select * from  sell_stats where max_price != sell_price;

but i am getting the error

ERROR 1111 (HY000): Invalid use of group function.

then i tried grouping them on id, but still the same error.

select * from  sell_stats where max_price != sell_price group by id;

please can anyone help me in this?

Shubham R
  • 7,382
  • 18
  • 53
  • 119
  • 2
    I don't see how you can get that error from the query you wrote. Group functions are things like `MAX()`, `COUNT()`, and `GROUP_CONCAT()`, and you have none of those in your query. – Barmar Nov 10 '16 at 05:44
  • 1
    Your query works fine: http://www.sqlfiddle.com/#!9/7a302/1 – Barmar Nov 10 '16 at 05:47
  • 1
    Agree with @Barmar. I guess the error raised from the other query, not this one. – Hermanto Nov 10 '16 at 05:47
  • I looked at several other SO questions about "Invalid use of group function". They all had functions like that in the `WHERE` clause, such as `WHERE sell_price != MAX(price)`. – Barmar Nov 10 '16 at 05:53
  • I am trying to your query but i can't find any issue. – pawan sen Nov 10 '16 at 05:55

1 Answers1

-2

Try this:

select * from  sell_stats where max_price <> sell_price;
FDavidov
  • 3,505
  • 6
  • 23
  • 59
  • 1
    Why would that be any different? `!=` and `<>` are interchangeable. – Barmar Nov 10 '16 at 05:46
  • Indeed, I normally use `<>` and I know that this statement is correct. – FDavidov Nov 10 '16 at 05:47
  • But why would using `!=` cause an error about group functions? – Barmar Nov 10 '16 at 05:49
  • 1
    My guess is that the he is (unaware) running several statements at the same time (imagine you have Workbench and a query sheet with several selects), and the error is triggered by the last. Another possibility is that we are not seeing the complete query (like tokas suggests). – FDavidov Nov 10 '16 at 05:52
  • Indeed. That's why I wouldn't waste time posting an answer until we get the real picture. Suggesting that he change `!=` to `<>` is an obvious waste of time. – Barmar Nov 10 '16 at 05:54
  • See? Many times (at least in my case) getting obvious suggestions/answers to questions caused me to re-think and solve the problem by myself. I see this forum as a channel through which we ALL get help in any possible way. In this case, it took me 10 secs to post my answer, and I'm willing to spend this time if it is of help. That is my way of honoring the people that created this fantastic site. Of course, this is only my personal opinion and nobody is forced to agree with me. – FDavidov Nov 10 '16 at 05:58
  • IMHO, posting an answer that can't possibly be right is bad. The OP will waste time trying to use it to see if it helps, instead of clarifying the question. Use the comments section to try to get him to clarify the question, then we can get back to the work of solving real problems. – Barmar Nov 10 '16 at 06:02
  • OK, I respect your position but select to exercise my freedom to disagree. Thank you anyway for your thoughts. – FDavidov Nov 10 '16 at 06:04
  • And I hope you respect my freedom to downvote. I didn't single you out, I also downvoted the answer that suggested `NOT max_price = sell_price`, since it's just as worthless. – Barmar Nov 10 '16 at 06:05
  • No problem, don't worry. I do it for the fun, not for the points. – FDavidov Nov 10 '16 at 06:07