3 ms·
Sometimes with complex queries, it can be tough to adhere to a simple set of style rules while also making clear where things like logical units start/stop. Do
by sbuttgereit 10y ago
Sometimes with complex queries, it can be tough to adhere to a simple set of style rules while also making clear where things like logical units start/stop. Don't get me wrong I'm not disagreeing with you in principle; but acknowledging that the declarative nature of the language cause you to break style for the sake of readability in some cases. I'm not going to post an example of such a case (I'd have to go digging and I'm too tired).
On a different note, I don't like a lot of the styles I do see. I like yours, with the exception of the joins. My convention is a bit different:
SELECT
members.firstname as "First Name"
,members.lastname as "Last Name"
FROM borrowings
JOIN books
ON borrowings.bookid = books.bookid
JOIN members
ON members.memberid = borrowings.memberid
WHERE books.author = 'Dan Brown';
Some of that is old habit (like the comma first thing which I know is out of favor with many) which I found useful when working with long column lists. I'd also typically and systematically alias the tables, but that wasn't done in the examples. Outside of tastes, the only real downside I run into is that it's easy to get too far to the right with the indentation style I use. But it's not that often that I get there.
- Semiapies 10y agoI haven't had trouble with complicated queries with this style. I've been doing it for ages, though. There nothing wrong with comma-first, it's sensible; I just never got into the habit. My joins are so I can instantly glance over the tables involved in a query. (And, oh yes, I, too, normally alias the crap out of tables if there's more than one in a query.)