Hey guys,

                This may be more of a question about the SQL language
itself rather than SQLite.  I'm finding inner join statements to be more
verbose than they should be and I'm curious if there is any sort of
syntax sugar that can be done to shorten them. 

 

An Example:

                CREATE TABLE tblA( col1 integer, someValue integer);

                CREATE TABLE tblB( col1 integer, fkcol integer, foreign
key (col2) references tblA(col1));

 

                My current query looks something like this:

                SELECT tblA.someValue from tblB inner join tblA on
tblB.fkcol = tblA.col1 where tblB.col1 = ?

 

                Couldn't it just be:

                SELECT fkcol.someValue from tblB where col1  = ?

 

                The reasoning here is that SQL knows the schema of tblB
and knows exactly where the FK is pointing to.  If  fkcol was pointing
to an invalid row or was null, fkcol.someValue could be null.  It seems
like this would just be syntax sugar and both should  generate the same
query plan.  The other thing I like about this syntax is that it would
have to throw an error if fkcol wasn't a true FK.  In this example, the
inner join line was fairly short, but it gets pretty intense when you
have multiple inner joins.

 

Thoughts?

 

-Shaun

 

 

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to