I had a discussion with a teammate on the topic whether the terms clause
and expression
can be used interchangeably. For example, is it correct/common to call a variable that stands for an expression
a=b
(e.g. that participates in a statement SELECT * WHERE expression
) a clause?
It would be useful is someone could give precise definitions of what clause
, expression
and statement
are in SQL world.
In SQL Terms, "clause" is usually used to refer to a section of a statement, usually introduced by the keyword it's named after - e.g. a typical SELECT
statement would be composed of a SELECT
clause, a FROM
clause and a WHERE
clause. Within the FROM
clause, some people may refer to JOIN
clauses and ON
clauses. However, this is by no means 100% accepted usage.
When it comes to "statement" and "expression", it's fairly standard usage - an expression is something that produces a value. In most languages, this is understood, further, to be something that produces a scalar value. In SQL, this is slightly modified because when you encounter an expression when working with a row set, the expression will produce one scalar value per row (or per group or partition, if grouping or partitioning are involved and it's in the relevant location).
Finally, a statement is a complete "something" that your database engine can understand and produce results for. It doesn't produce a value but it may produce a result set. You can't just send a FROM
clause to the database - it has to be part of a larger statement, such as the SELECT
statement I mentioned in my first paragraph.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With