3 ms·
Isn't that what a common table expression is? Basically a pseudo temp-table to break down queries. Of course, they also allow recursion, which you can't do with
by briHass 4y ago
Isn't that what a common table expression is? Basically a pseudo temp-table to break down queries. Of course, they also allow recursion, which you can't do with a temp table.
- tremon 4y agoYes, but a common table expression is still bound to only one query. You can use it multiple times within the same query, but you still can't save a common table expression in a variable and re-use it in multiple queries. This is what I'd what to do if common table expression really were common: SELECT c1, c2 FROM DifficultJoinStructure AS myCte; WITH myCte SELECT c1, c2 WHERE SomeCondition(c1); WITH myCte SELECT c1, c2 WHERE SomeCondition(c2);
- TristanBall 4y agoSo.. a view then? Granted most environments effectively treat views as DBA/Sysadmin owned objects, especially where end users/apps are effectively sharing one, or a small number, of user accounts. But given user=schema aspect several of the traditional databases, I get the impression the original intent might have been a little more laissez fair? Of course the same can be said for tables, and that was perhaps a little idealistic! Views aren't always quite as composable as you'd like either, or maybe I'm just scarred by the particular DB engines I use most. So I actually agree with you, but unfortunately SQL requires that the "WELL AKSHWELLY" be followed by one or more "BUT" clauses.