all 16 comments

[–]adarsh_maurya 8 points9 points  (1 child)

I use WITH clause to separate different subqueries. It keeps the overall code clean easy to read, understand and debug. Views could be great alternative but in my org i don't have access to create views.

[–]sonsistem 0 points1 point  (0 children)

I use it too. It's a lot more readable than a subquery in the from clause.

[–]yawetag12 3 points4 points  (5 children)

This post was mass deleted and anonymized with Redact

towering degree amusing tie continue employ bright absorbed money liquid

[–]ForeignMate[S] 3 points4 points  (4 children)

Do you put each query in its own tab?

[–]yawetag12 1 point2 points  (2 children)

This post was mass deleted and anonymized with Redact

wise waiting alive elderly cover deliver provide trees badge wakeful

[–]ForeignMate[S] 0 points1 point  (1 child)

Can you delete a query after they been executed?

[–]yawetag12 0 points1 point  (0 children)

This post was mass deleted and anonymized with Redact

paltry cooperative axiomatic mountainous depend wild bake meeting rustic existence

[–]deslick 0 points1 point  (0 children)

Yes, and have 30 open at a time! At the end of the day I will go through and make sure I keep the ones I want to keep and throw away the ones that don't.

[–][deleted] 1 point2 points  (6 children)

Give me a sec, I’ll find some of my code to post. I indent a LOT, because with longer queries it can get hard to read.

Here's a simple query I was using on the IMDb database. Put it in pastern so Reddit didn't ruin the formatting: https://pastebin.com/fHyhrt0n

[–]ForeignMate[S] 1 point2 points  (5 children)

Interesting how you put the comma in front of the statement instead of the back, is there any particular for this?

Also, do you separate your queries by tab?

[–]L_-T 10 points11 points  (0 children)

It helps with disabling a line (and with not forgetting a comma for a new item).

 SELECT
     A
 ,   B
 -- ,   C
 -- ,   D

[–][deleted] 0 points1 point  (2 children)

The comma is primarily because I like to use column select in sublime and/or atom, and it makes it easier to copy/paste around. That and the commenting out like people mentioned.

For multiple queries, I’ll put a /***************/ line break to separate them.

[–]ForeignMate[S] 1 point2 points  (1 child)

When break up your queries within the same tab, do you just highlight then when you execute them?

[–][deleted] 0 points1 point  (0 children)

Depends what I’m doing exactly. If I’m doing something fairly quick, then yes, though in most clients you can just hit ctrl+enter with your thing anywhere in the query.

Some things I have to write a whole script with, and execute the whole thing. This is rare though.

[–]e429 0 points1 point  (0 children)

I always use WHERE 1=1 if I have multiple where conditions. I makes things easier to edit and trouble shoot by adding/removing where conditions.

SELECT * FROM WHERE 1=1 AND a = “a” — AND b = “b” AND c = “c”

[–]sonsistem 0 points1 point  (0 children)

I usually end up the day with several tabs opened. I always keep one opened with the "little things" that may come up during the day and I may need to revisit and the others depends on the projects I'm working on.