Skip to Content.
Sympa Menu

freetds - Re: [freetds] SQL nested querys

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Ricardo Quintal <rquintalr_76 AT yahoo.com.mx>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] SQL nested querys
  • Date: Tue, 22 May 2007 16:02:29 -0500 (CDT)

Hi Duncan, i understand all about primary key, indexes, relationship and the
use of inner join, left join.. Maybe my example was too easy, sorry. My point
here that some cases i have to use the key of the first query in a second
query (nestead). This because the structure of the tables were maked bad.

If I made a first query when I need to make another I have to call a
dbcancel();
doing this i clear my buffer of the first sql sentence.

How can I do that.

Thanks

Duncan Berriman <duncan AT dcl.co.uk> escribió:
To answer you question directly yes this should be possible but why not
simply use a join?

Select d.descripcion from detalle d, aceros a where d.idkey = a.idkey

Always use a join (that's the point of SQL) where you can, it's a lot faster
as the data set is built on the server and done in one query. If your aceros
table holds a 1000 rows your solution will cause 1001 sql queries to be
parsed and run over odbs which will take a lot longer.

I guess you should also have a primary key on a.idkey and a key of some sort
on d.description although the above query will cause a full table scan
anyway as there is no where clause on aceros that limits the data returned.

If you need to limit the data returned in some way then simply add it to the
where clause.

Duncan

> -----Original Message-----
> From: freetds-bounces AT lists.ibiblio.org
> [mailto:freetds-bounces AT lists.ibiblio.org] On Behalf Of
> Ricardo Quintal
> Sent: 22 May 2007 15:46
> To: freetds AT lists.ibiblio.org
> Subject: [freetds] SQL nested querys
>
>
> Hi !!! I'm more or less new using freetds and I have a
> question about it.
>
> How can I make nested querys if I have a principal query
> and a data result from it is necesary to pass to another
> query inside of a cycle.
>
> result = execsql("Select IdKey from Aceros");
>
> while (result == 0)
> {
> result = execsql("select descripcion from detalle where
> idkey = %d",idkey);
> }
>
> Is this possible ??
>
> Thanks in advance
>
> Ricardo
>
>
> ---------------------------------
>
> Llama gratis a cualquier PC del mundo.
> Con una excelente calidad de sonido.
> Yahoo! Messenger
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>


_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds



---------------------------------
Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por
$100 al mes. http://net.yahoo.com.mx




Archive powered by MHonArc 2.6.24.

Top of Page