Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
Re: get max/min of subquery
Old
  (#1)
gil
Guest
 
Posts: n/a
Default Re: get max/min of subquery - 06-04-2007, 07:58 AM

On May 23, 4:30 pm, lark <ham...@sbcdeglobalspam.net> wrote:
> gil wrote:
> > hi,

>
> > i have a table with a column that is a scalar ("alert_key") .

>
> > my subquery is:

>
> > SELECT alert_key FROM `user` WHERE alert_key < 4000 ORDER BY alert_key
> > DESC LIMIT 100

>
> > this brings me 100 or less rows. now i need to find the minimum value
> > from the returned rows and with that value (call it MinValue) do
> > another SELECT :

>
> > SELECT alert_key FROM `user` WHERE alert_key > MinValue ORDER BY
> > alert_key ASC LIMIT 100

>
> > this looks kind of stupid, but the reason for this is that i allways
> > want to have 100 rows, therefore , if the first SELECT got only 50
> > rows, i want to take thes 50 rows + 50 more rows that are not <4000.

>
> > bottom line: how do i get the MIN of a subquery into a variable , all
> > in one statement.

>
> > thanks a lot,

>
> > gil

>
> have you tried something like this:
>
> SELECT alert_key FROM `user` WHERE alert_key > (SELECT min(alert_key)
> FROM `user` WHERE alert_key < 4000) ORDER BY
> alert_key ASC LIMIT 100
>
> --
> lark -- ham...@sbcdeglobalspam.net
> To reply to me directly, delete "despam".- Hide quoted text -
>
> - Show quoted text -


thanks for your reply.

this still doesn't solve my problem because it will allways bring the
minimum of all rows that are <4000, and not the minimum of the 100
rows smaller than 4000 order by alert_key DESC.this is why i need the
minimum of the subquery.

do you have another idea?

thanks again,

gil

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top