On Mon, 28 Jul 2014 16:20:38 -0400
Igor Tandetnik <[email protected]> wrote:

> On 7/28/2014 4:10 PM, Drago, William @ MWG - NARDAEAST wrote:
> > Can someone tell me what the purpose of line 2 is in the following
> > example? It seems redundant to me since what is wanted from the
> > Customers table is specified on line 1.
> 
> Line 1 - the SELECT clause - specifies what data you want returned.
> Line 2 - the FROM clause - specifies where you want to get that data
> from.

To elaborate a bit, the SELECT-FROM-WHERE construct is known to the
pointy-headed ones as an SPJ query: select-project-join.  Properly
speaking, the SQL SELECT states which *columns* are wanted; it is
analogous to the relational PROJECT operator.  

Tell you what, since we're talking databases, here's a table

SQL             Rel Alg Affects
------- ------- -------
SELECT  project columns
FROM    [join]  tables
WHERE   select  rows

To the OP's point, why is it necessary to state the FROM if it could be
inferred from first part of the column names?  It's just a design
choice, convenient and conventional.  

It's usually convenient because usually the column names don't require
tablename qualifiers:

        select a, b, c, d
        from T

would be more verbose and redundant if each column needed to be
qualified with "T.".  

It's also conventional in programming languages to name the data and
to pass those names as arguments to functions.  Consider the similarity
of 

        double d[] = { 16 };
        double r = sqrt(d[0]);

and

        insert into T(d) values (16);
        select sqrt(d) from T;

So, yeah, sometimes the tablename could be inferred.  But SQL has many
ills, and that's hardly the worst one.  

--jkl
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to