Hi Michael,
Well, the SQL Query you requested is exatcly the one I'm asking! :-)
Like I said in other message, I solved the problem using TWO queries. In
the first one I get the 10th date. In the second one I use this date to
LIMIT the result to what I want. But is not a question of solving the
problem, but a question for a better designed query. I just want to use 1
(one) select to do the same thing that the two selects above do, if it is
possible of course. Below, I will show you the actual scenary, and after,
the question, how can I optimize it to use just one select?. If I can get
the value of the LAST index, I can subtract 10 "indexes" from this value and
get only this range of values, doing this I will get the last ten dates
without the LIMIT 0,10 that don't give me what I want.
Actual scenary:
// This is the main select that give me the last ten dates.
$sql = "select pa.codigo,arquivo,label,tipo,DATE_FORMAT(data,'%d/%m/%Y -
%H:%i') as ndata,RS,ref_wicie from processo_arquivos as pa,cliente as
c,processo as p where pa.codigocliente=c.codigo and
pa.codigoprocesso=p.codigo ";
// This is the FIRST select that catch the LIMIT date
$sql2 = "select data from processo_arquivos as pa,cliente as c,processo as
p where pa.codigocliente=c.codigo and pa.codigoprocesso=p.codigo order by
data desc limit 0,11";
$conexao->Query($sql2,$this->banco,$this->valor);
$i = 0;
if ($conexao->Select($this->banco)){
while (($this->valor =
mysql_fetch_array($this->banco)) && ($i<10)){
$i++;
}
$dataLimite = $this->valor['data'];
$sql .= " and data>'".$dataLimite."' "; <--- Here I
select the last
ten dates.
}
What I wanted:
--- ??? ----
Just do what I'm doing above using only ONE select.
Any tips?
Best Regards,
Felipe
-----Mensagem original-----
De: Michael T. Babcock [mailto:[EMAIL PROTECTED]]
Enviada em: quarta-feira, 4 de dezembro de 2002 02:06
Para: [EMAIL PROTECTED]
Assunto: Re: RES: SQL Select Idea
On Tue, Dec 03, 2002 at 07:02:02PM -0200, Felipe Moreno - MAILING LISTS
wrote:
> 2) What I get is I use the SELECT * FROM processo_arquivos ORDER BY DATE
> DESC LIMIT 0,3 (considering that I only want 3)
[ that worked as described ]
> 3) The problem getting the result like this:
>
> Since I have a link in the header of the tabel that make the ORDER BY
work,
> when I select de COD after the result above, I should get:
[ you didn't give the EXACT SQL QUERY that you're typing in; please give
it ]
I'm assuming that you're forgetting a step, or misunderstanding a step
involved. Are you doing anything with that data you're selecting, or just
selecting it and leaving it? You might be wanting to select it into a new
table or something; look up "INSERT INTO ... SELECT FROM ...".
--
Michael T. Babcock
CTO, FibreSpeed Ltd. (Hosting, Security, Consultation, Database, etc)
http://www.fibrespeed.net/~mbabcock/
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php