Lurker News

Comments (112) 38 threads

dm85 replies#
This is good intiative. We need to simplify pedagogy.

On a related note, I always found the syntax of SQL to be great. Someone told me that simplicity of SQL made relational databases even more popular. It is one of the best designed language where even someone new to the field won't feel intimidated. I'm surprised designers of SQL haven't won the Turing Award yet.

wvenable4 replies#
I teach SQL to financial people and, for the most part, it isn't too bad. When I get to joins, I teach a subset of SQL where all joins are done through INNER JOIN / LEFT JOIN syntax and that helps a lot. Joins are the part that everyone has trouble with.
setr1 reply#
Tbh I usually see teachers worried about joins but its the group by/having clauses that I always watched people struggle with (at least, writing it).

Ofc that might just be the emphasis on joins makes group by the next lowest hanging fruit

ranit2 replies#
What do your abbreviations mean?

Continue this thread — 2 replies

Exuma2 replies#
Can you explain when to really use a lateral join?
garyclarke271 reply#
In Postgresql, Lateral Joins enable function chaining for set returning functions. ie you can feed the results of earlier srf function to the arguments of following function. This gets around one of Postgresql most glaring omissions - table valued parameters. Is incredibly useful once you get used to them.

Continue this thread — 1 reply

netcraft#
In my experience it’s relatively rare that you need them. I think of them as the for-each of joins. It evaluates row by row, not a single time. Another analogy would be a correlated subquery.
HeavyStorm#
The syntax isn't the problem though. Join relational operation is though on itself.
lixtra1 reply#
I write a lot of sql and it is generally a nice language.

But for my taste the language is to close to English and therefore redundant and inconsistent in an annoying way. Example:
Select x from tbl ...
Delete from tbl ...
Update tbl set x=...
Why change the word order?

garyclarke27#
Yes,I also suggest standards committee allow the option of putting FROM clause first - this would make it easier for beginners to grok what’s going on and enable better tooling such as auto-complete.
hyperpallium1 reply#
Since there weren't any commercial relational databases available pre-SQL, this is quite true.

Codd wrote a couple of query languages before, but they apparently weren't usable by mere mortals.
SQL is over 40 years old, and still dominates. The most recent contenders had to position themselves in terms of SQL (NoSQL).

codeisawesome#
Also interesting how even NoSQL (non relational) Data stores are embracing SQL or some subset or flavouring of it.
pjmlp#
On PC the alternatives were xBase, FoxPro, Paradox and Access, so it was a no brainer that SQL eventually took over.
m_st7 replies#
I agree except one thing: SELECT cols FROM table. This should really be FROM table SELECT cols as every modern SQL editor will then be able to show you a list of available columns.

See LINQ. There they had the opportunity to fix it and it works just great.

jrockway1 reply#
I mean, it works either way. Once you type the column names, it can guess the table name easily.

I use DataGrip at work and it can complete the column names without knowing the table name, so it ends up not being a problem.

dragonwriter#
> Once you type the column names, it can guess the table name easily.

If the query is simple enough that a natural join would work and you aren't doing FROM clause aliasing (which can be useful to make reusable queries self-documenting), sure.
For more complex queries and obviously any time table or column aliasing are used, that becomes somewhere between less likely and logically impossible.

sqldba#
It’s also how azure query language works.
techno_modus#
I personally think first about the loop/iterator organization (FROM in SQL) and only after that what I am going to do with its elements.

However,

    SELECT a1,a2,... FROM Table AS t WHERE Condition
is syntactically equivalent to Python list comprehension:

    [(t.a1,t.a2,...) for t in Table if Condition]
Here the use of attributes (SELECT) is also written before the iterator.

SELECT is also analogous to normal loops:

    foreach t in Table
      if not Condition: continue
      # Use t.a1, t.a2 etc.
Here we first provide the loop specification while the usage of elements is written only in the body.
lozzo#
I concur. I always start with select * from table because I cannot possibly remember all the right column names
piaste1 reply#
More generally, statements should appear in the same order as they are executed, as far as this is possible.

This nullifies some other common sources of confusion, such as which statements are executed before a GROUP BY and which ones after (and why HAVING exists as a keyword). It's also similar to how CTE syntax is generally much more readable than subqueries.

hesk#
The order of clauses in a SQL statement should have no relation on the order of execution because SQL is a declarative query language. The query specifies what the user wants and not how the system should compute the answer.

This declarative property also provides a (somewhat weak) motivation of why SELECT should come first. Precisely because it answers part of the WHAT, i.e., the schema of the result.

icc97#
I'd rather have the enjoyment of being able to think in normal English speak rather than Yoda speak just to fix one edge case that appeared decades after they came up with the syntax.
nexxer#
In the clients I've used (SQLYog, Mysql Workbench), aliasing a table lets you use autocomplete when referencing that alias followed by a dot.

So, I will start with a SELECT * FROM myTable t, then go back and replace * with t..
I'll use the same in other places in the query like WHERE conditions.

SwellJoe3 replies#
This is gorgeous, and a great topic. No matter what field you're working in, understanding databases is extraordinarily valuable...and SQL is among the longest lasting techs I've ever learned (e.g. name another programming language that is as valuable today as it was 20 years ago, if not moreso). Even with the rise of NoSQL databases, I suspect we'll all still need to know a little SQL in another 20 years (and it was already more than 20 years old when I first encountered it in the 90s). And, even if not the same language, conceptually understanding how to query data is probably timeless.
Hendrikto4 replies#
> name another programming language that is as valuable today as it was 20 years ago, if not moreso

* C
* Python
* Java
20 years ago was 1998.

Cyph0n2 replies#
C I agree with.

But Java and Python? Both languages have changed beyond recognition over the past 20 years. A programmer who hasn't touched either for 20 years would probably be overwhelmed.
Another difference is that even though SQL has changed, there isn't much you need to know outside of the DBMS you are using. With Java and Python on the other hand, you need to keep up with the changing library landscape to stay relevant.

setr#
>With Java and Python on the other hand, you need to keep up with the changing library landscape to stay relevant.

For C, its just library management is troublesome enough that you end up writing your own ;)

kbenson#
Perl. And no, that's not just a factor of its current popularity, as the language has evolved and has regular releases.

Perl has amazing backwards compatibility, but has also solidified on much better coding practices and libraries in the last 20 years. You can still run that code from 20 years ago with a new interpreter and it will be safer and faster, or you can choose a more modern style or library and it will work just as well.
And to forestall anyone trying to bring up Perl 6 as a counterargument, unless you actually know what it is and how it interacts with Perl 5 and the community, I doubt the argument is actually saying what you think...

SwellJoe#
Sure, and I still use Perl as my primary language, just as I did 20 years ago, with some forays into other languages (like Python and C) along the way. But, this is survivor bias (one could argue SQL is also benefiting from survivor bias, though SQL was the dominant data query language then and it is the dominant data query language today, whereas one could argue only C was/is dominant in its space at both points in history). But, where's Pascal, Visual Basic (or Basic of any sort), Tcl, etc.? There's dozens of other languages that came and went, including data-oriented languages. All of which were popular during the 90s, and effectively gone now. And, only C among your examples is actually exhibiting the same kind of longevity (SQL is more than 40 years old, so it predates Python, Java, Perl, etc. by quite a lot)...I probably should have put the starting point for this thought experiment at 30+ years ago, but 20 years ago is when I first started using SQL, so it's what I used, which isn't really useful. Who cares when I learned the value of SQL, when it's an industry-wide phenomenon?

My point wasn't that one can't name languages with staying power. There are several. But, SQL is still special, I think. It's almost universally needed. If you go to work in a Node or Go shop today, you're probably still gonna need to know some SQL, just like if you went to work in a Python or Perl or Java shop in the 90s.

collinmanderson#
JavaScript is probably also more valuable than it was in 1998. Still pretty much backwards compatible, too.
s_dev#
Pretty sure SQL has been around far longer than either Java or Python.
corpMaverick#
To your point. I learned SQL almost 30 years ago. Along Unix, vi, Perl it is a skill that I still use often. It is one of the best learning investments that I ever made.
dragonwriter#
>e.g. name another programming language that is as valuable today as it was 20 years ago, if not moreso

If we include non-Turing-complete languages as “programming languages”, which we must for SQL to get that 20-year label since SQL wasn't Turing-complete until recursive CTEs were part of the language, then XML.
Also, even without that caveat, candidates include Bash, C, C++, Objective-C, Perl, elisp, Java, JavaScript, MATLAB, VHDL, and others. Some, while still being as useful as they were 20 years ago, are down from a peak in the intervening period, but arguably that's true of SQL, as well.

djrobstep2 replies#
The choice of example database (the death penalty) is terrific.

So much more interesting, important and compelling than the usual tired customer/product examples.
I'm tired of seeing the implicit assumption around the place that software is just about business. Software should be about more than that.

lixtra1 reply#
I'm not the guy for trigger warnings but I find the choice of data unfortunate. There is a big percentage of people I won't recommend the page because of the dataset.
nnm#
same here.
swaggyBoatswain#
I like the death penalty database, it makes things so much more interesting and memorable. Data doesn't have to be boring
m_st1 reply#
Congratulations! I love this kind of interactive tutorials as their helping more and more people learning stuff without a boring book and no exercises.

That said: Doesn't work in Firefox and Edge? Common, are we back in 1998? Sorry for the rant, but please don't do that.

enz#
It works pretty fine on FF. However, you have to enable `dom.webcomponents.customelements.enabled` manually...

Load more comments