Jump to content

Recommended Posts

hmm, okay so i have a query and i want to select the eventName based on the biggest number, but MAX apparently can't be used in the WHERE clause, any help, here is what i attempted

 

SELECT `eventName` FROM events WHERE `addedToScheduleCurr` = MAX(`addedToScheduleCurr`)

 

any idea on how else i could do this

 

thanks,

john

 

p.s.

phpMyAdmin error says

#1111 - Invalid use of group function

Link to comment
https://forums.phpfreaks.com/topic/83652-solved-selecting-highest-field/
Share on other sites

that returns all the events with different names, and if i group by addedToScheduleCurrthen it returns all of the addedToScheduleCurr with different number.  I'm attempting to only retrieve the highest addedToScheduleCurr event name and avoid using 2 sql statementS such as

 

SELECT MAX(addedToScheduleCurr) FROM events

 

and then

SELECT eventname, FROM events WHERE addedToScheduleCurr = '$resultFromPreviousSQlStatement'

mysql returns an error when MAX() function is used in the WHERE statement

 

hmm I'm not quite sure if everyone is understanding what I'm asking either so i'll try to re-explain it

 

lets say i have a table that looks like

 

eventName    addedToScheduleCurr

 

event1              10

event2              9

event3              28

event4              15

event5              19

 

i need an sql statement that will  pull out "event3" becuase of the fast that it has the highest value in the addedToScheduleCurr column

 

eventName    addedToScheduleCurr

 

event1              15

event2              7

event3              9

event4              35

event5              42

 

in the above example it would pull out event5 because it has the highest addedToSceduleCurr column

 

i'm starting to think this might have to be 2 separate quires...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.