Thread: join syntax

join syntax

From
Jodi Kanter
Date:
One of my colleagues has created a database where he has the same field name in two tables and uses this field to link
histables rather than some arbitrary value. For example, he has used "exp_id" in two tables. When writing his joins he
usesa syntax that says something like JOIN ON EXP_ID. Can someone tell me what that syntax should be? I am not very
familiarwith it since I typically use the syntax where one field is set equal to the other.<br /> Personally I prefer
notto set databases up this way but cannot seem to convince him of this. And yet I am supposed to now help him with his
databaseand application.. Is there some documentation that would define this type of syntax? How is this handled if you
havemore than one table in the join? It does not appear that this format would allow for this.<br /> Thanks<br />
Jodi<br/><div class="moz-signature">-- <br /></div><div class="Section1"><p class="MsoNormal"><i><span
style="font-size:9pt; font-family: Arial; "> _______________________________<br /></span></i><i><span style="font-size:
10pt;">Jodi L Kanter<br /> BioInformatics Database Administrator<br /> University of Virginia<br /> (434) 924-2846<br
/><ahref="mailto:jkanter@virginia.edu">jkanter@virginia.edu</a> </span></i><span style="font-size: 11pt; font-family:
Arial;"><br style="mso-special-character:line-break" /><br style="mso-special-character:line-break" /></span><p
class="MsoNormal"><spanstyle="font-size: 11pt; font-family: Arial; ">  </span><p class="MsoNormal"><i><span
style="font-size:9pt; font-family: Arial; ">  </span></i><p class="MsoNormal"><i><span style="font-size: 9pt;
font-family:Arial; ">  </span></i></div> 

Re: join syntax

From
Josh Berkus
Date:
Jodi,

> One of my colleagues has created a database where he has the same field
> name in two tables and uses this field to link his tables rather than
> some arbitrary value. For example, he has used "exp_id" in two tables.
> When writing his joins he uses a syntax that says something like JOIN ON
> EXP_ID. Can someone tell me what that syntax should be? I am not very
> familiar with it since I typically use the syntax where one field is set
> equal to the other.

table_a JOIN table_b USING (exp_id)

> Personally I prefer not to set databases up this way but cannot seem to
> convince him of this. And yet I am supposed to now help him with his
> database and application..

That, we can't help you with.

Point out to your friend, though, that an explicit JOIN order can often harm
performance when the JOIN order given by the query writer is not ideal.  That
is, the "FROM table, table, table WHERE expression, expression" syntax gives
the parser a freer hand to choose the fastest execution method.  Of course,
on a very small database that typically makes litte difference.

--
-Josh BerkusAglio Database SolutionsSan Francisco



Re: join syntax

From
"scott.marlowe"
Date:
On Tue, 17 Jun 2003, Jodi Kanter wrote:

> One of my colleagues has created a database where he has the same field 
> name in two tables and uses this field to link his tables rather than 
> some arbitrary value. For example, he has used "exp_id" in two tables. 
> When writing his joins he uses a syntax that says something like JOIN ON 
> EXP_ID. Can someone tell me what that syntax should be? I am not very 
> familiar with it since I typically use the syntax where one field is set 
> equal to the other.
> Personally I prefer not to set databases up this way but cannot seem to 
> convince him of this. And yet I am supposed to now help him with his 
> database and application.. Is there some documentation that would define 
> this type of syntax? How is this handled if you have more than one table 
> in the join? It does not appear that this format would allow for this.

If you're joining two tables on a field that has the same name you can use 
a natural join.

select * from table1 natural join table2;



comparing querys

From
Lucas Lain
Date:
how can i compare two querys' eficiency???

TIA,

-- 
Lucas Lain
lainl@aconectarse.com
#! /Scripting/Manager (??)


Re: comparing querys

From
Rod Taylor
Date:
Take a look at EXPLAIN and EXPLAIN ANALYSE:

http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=sql-explain.html

On Wed, 2003-06-18 at 16:23, Lucas Lain wrote:
> how can i compare two querys' eficiency???
>
> TIA,
--
Rod Taylor <rbt@rbt.ca>

PGP Key: http://www.rbt.ca/rbtpub.asc