List:General Discussion« Previous MessageNext Message »
From:Felipe Moreno - MAILING LISTS Date:December 4 2002 10:55am
Subject:RES: RES: SQL Select Idea
View as plain text  
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";
			$i = 0;
			if ($conexao->Select($this->banco)){
				while (($this->valor = mysql_fetch_array($this->banco)) && ($i<10)){
				$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,


-----Mensagem original-----
De: Michael T. Babcock [mailto:mbabcock@stripped]
Enviada em: quarta-feira, 4 de dezembro de 2002 02:06
Para: mysql@stripped
Assunto: Re: RES: SQL Select Idea

On Tue, Dec 03, 2002 at 07:02:02PM -0200, Felipe Moreno - MAILING LISTS
> 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
> 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)

Before posting, please check:   (the manual)           (the list archive)

To request this thread, e-mail <mysql-thread126499@stripped>
To unsubscribe, e-mail <>
Trouble unsubscribing? Try:

Blob accepts LongBlob without errorRyan @ Common Ground . To3 Dec
  • re: Blob accepts LongBlob without errorVictoria Reznichenko3 Dec
    • SQL Select IdeaFelipe Moreno - MAILING LISTS3 Dec
      • RE: SQL Select IdeaMike Hillyer3 Dec
      • RE: SQL Select IdeaJim Esten3 Dec
        • RES: SQL Select IdeaFelipe Moreno - MAILING LISTS3 Dec
          • Re: RES: SQL Select IdeaMichael T. Babcock4 Dec
            • RES: RES: SQL Select IdeaFelipe Moreno - MAILING LISTS4 Dec
              • Re: RES: RES: SQL Select IdeaMichael T. Babcock4 Dec
                • RES: RES: RES: SQL Select IdeaFelipe Moreno - MAILING LISTS5 Dec
        • RE: SQL Select IdeaJim Esten4 Dec
Re: Blob accepts LongBlob without errorJan Steinman3 Dec