freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Duncan Berriman" <duncan AT dcl.co.uk>
- To: "'FreeTDS Development Group'" <freetds AT lists.ibiblio.org>
- Subject: Re: [freetds] SQL nested querys
- Date: Wed, 23 May 2007 07:49:30 +0100
Probably depends on the exact database being used. So you'd have to try it.
Using mysql (as I have it to hand) it appears the two are pretty much equal.
In my example database both result in the primary key being used on the 2nd
table (Aceros) and no apparent difference in the number of rows visited by
the query.
Duncan
> -----Original Message-----
> From: freetds-bounces AT lists.ibiblio.org
> [mailto:freetds-bounces AT lists.ibiblio.org] On Behalf Of
> Thomas, Christopher (LLU)
> Sent: 23 May 2007 01:26
> To: FreeTDS Development Group
> Subject: Re: [freetds] SQL nested querys
>
>
> I'm not a sql expert but I'm guessing the query:
>
> Select d.descripcion from detalle d, aceros a where d.idkey = a.idkey
>
> Will execute faster than the query:
>
> select descripcion from detalle where idkey in(Select IdKey
> from Aceros)
>
> Right?
>
> Chris
>
> -----Original Message-----
> From: freetds-bounces AT lists.ibiblio.org
> [mailto:freetds-bounces AT lists.ibiblio.org] On Behalf Of Igor Korot
> Sent: Tuesday, May 22, 2007 2:42 PM
> To: FreeTDS Development Group; FreeTDS Development Group
> Subject: Re: [freetds] SQL nested querys
>
> Ricardo,
> Why you couldn't use the sub-queries?
> Just try to pull the data using the isql or Query Analyzer
> (just to make sure
> you pulling ther right data), and then use the same query
> inside your program.
>
> Thank you.
>
> -----Original Message-----
> >From: Ricardo Quintal <rquintalr_76 AT yahoo.com.mx>
> >Sent: May 22, 2007 5:02 PM
> >To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
> >Subject: Re: [freetds] SQL nested querys
> >
> >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
> >_______________________________________________
> >FreeTDS mailing list
> >FreeTDS AT lists.ibiblio.org
> >http://lists.ibiblio.org/mailman/listinfo/freetds
>
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
> _______________________________________________
> 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] SQL nested querys,
Ricardo Quintal, 05/22/2007
-
Re: [freetds] SQL nested querys,
Duncan Berriman, 05/22/2007
- Re: [freetds] SQL nested querys, Ricardo Quintal, 05/22/2007
- <Possible follow-up(s)>
-
Re: [freetds] SQL nested querys,
Igor Korot, 05/22/2007
-
Re: [freetds] SQL nested querys,
Thomas, Christopher (LLU), 05/22/2007
- Re: [freetds] SQL nested querys, Duncan Berriman, 05/23/2007
-
Re: [freetds] SQL nested querys,
Thomas, Christopher (LLU), 05/22/2007
-
Re: [freetds] SQL nested querys,
Duncan Berriman, 05/22/2007
Archive powered by MHonArc 2.6.24.