r/SQL • u/badboyzpwns • May 20 '26
PostgreSQL What are common SQL red flags?
Hello! interview prepping, here wondering what are some common red flags for wrioting SQL?
Like
LIKE failing to index, not having trasnactions, usign SELECT * instead of specific collums, etc š
53
Upvotes
246
u/pilesofbutts May 20 '26
Others may have differing opinions but I personally hate a b c aliases for joins. I prefer SQL join aliases to be an abbreviation for the table name. e.g. contact_info is aliased to ci. it helps with readability in my opinion.
71
u/wildjackalope May 20 '26
Not a big one and my OCD is probably showing but Iāve passed on weak candidates who also donāt format their code for readability. It sounds petty, but the behavior and weak skills/ inexperience seem to go hand in hand in my personal experience.
22
u/JaceBearelen May 20 '26
Iāve had a few sql tech interviews. All kinda went the same way.
Theyāre gonna give you a database on some coding platform and ask you to find the second highest seller or some other question that needs a bit more than select * from a join b. Then theyāll ask you to modify it or move on to another question, rinse, repeat.
All thatās really important is that you can explain what youāre doing and ask clarifying questions.
94
u/dab31415 May 20 '26
Writing in complete sentences
Spelling
Proof reading
18
u/Basic_Reporter9579 May 20 '26
select * from table1 t1, table2 t1 where t1.id=t2.col1
35
u/BigBagaroo May 20 '26
I am an old fart. I want to see INNER JOIN or LEFT OUTER JOIN. I know that JOIN is an inner join, I just like to read it. It stands out more
12
u/connor-brown May 20 '26
Is failing to index a query a red flag? I donāt think Iāve indexed anything but really big queries in months and I use sql everyday
33
u/danmc853 May 20 '26
Fixing duplicate rows with a select distinct instead proper joins
39
u/iama_bill May 20 '26
Lower case
SELECTfollowed by upper case keywords. Canāt trust em.10
u/GunnerMcGrath May 21 '26
It probably wouldn't come up in an interview but if I see a cursor I assume you're incompetent.
7
u/jfrazierjr May 21 '26
Cursors. There's almost always a better way to do it
29
u/vertigo235 May 20 '26
Using RIGHT JOINS š
6
u/sandrrawrr May 21 '26
I'm really guilty of this when I was early in my SQL career, but multiple nested statements rather than just turning it into a CTE. Sure, nests are a bit easier to comment out when you're testing data, but a well written CTE will save you so much time.
18
u/kagato87 MS SQL May 20 '26
DISTINCT is a warning sign. It often suggests an issue in your joins or your schema design.
When you find yourself wanting to use it, take a step back and ask, is there a better way? Is this really correct, or could it be masking a problem?
4
u/vintagegeek May 20 '26
In my interview, I was asked for a quick python program to reverse a text input. That's it. They asked me nothing about SQL, and my job 100% relies on SQL. After four years working here, I asked my boss why. He said "You can't know everything, but you can learn anything".
6
u/billbot77 May 20 '26
Loops or cursors. There is always a better way (unless you are executing meta code)
3
u/DexterHsu May 21 '26
If you are asking this is probably too late , just stick with the cheatsheet you find on google search
3
u/ChristianPacifist May 21 '26
These supposed red flags can vary by version of SQL and specific use case.
Indexing for instance can be needed in something like Oracle or SQL Server depending on the use case, but it is not even possible in Snowflake. Snowflake also can be very slow with SELECT *, but this is not a problem in other languages.
3
u/SkinnyInABeanie May 21 '26
Right Join š
12
u/hipsterrobot May 20 '26
Leading commas. Come at me! š
8
u/twillrose47 maybeSQL May 20 '26 edited May 20 '26
Common one I've encountered over the years and ones I always bring up when I teach SQL:
There are always really hyper-specific "gotchas" that I personally find to be quite poor taste from the interviewer -- if it's not likely to be used in practice and purely a "do you understand all possible nuances", this sort of thing is just intellectual flexing I can do without -- the job itself is the red flag.
Good luck to ya
2
u/paultherobert May 20 '26
Great blog on this: SQL Code Smells. In this article, I cover SQL code⦠| by Carl Anderson | Medium
2
u/aarontbarratt STUFF() May 20 '26
Not sure if this counts!
But using an ORM with 14 billion dependencies to write simple select statements
Also, prefixing every column with its data type. I never want to see
sFoooriBarEVER2
u/SoggyGrayDuck May 21 '26
Mlfrom my last job, multi thousand line pieces of code.
It actually likely made sense when it was created but it made parallel processes impossible.
2
u/Sexy_Koala_Juice DuckDB May 21 '26
Not using modern features. SQL has improved a lot over the years, we donāt have to write long ass queries when you could just use the new features to achieve the same thing more concisely
2
u/cheesecakegood May 21 '26
4 typos in two sentences?
2
u/lalaluna05 May 21 '26
Aggregating arbitrarily to eliminate duplication. (āArbitrarilyā being the key word.)
Select distinct. Sometimes warranted but usually not. I try to normalize without doing this.
No comments or notes.
Scanning entire tables multiple times for the same query instead of filtering early.
Select splats, which you already noted. Good for quick checks, not good for long queries especially that get changed or built out over time.
These are all things I fixed today actually š
2
u/Common-Author-8441 May 21 '26
using a CROSS JOIN with a really long WHERE clause
2
u/Dead_Parrot May 21 '26
I was in a video call yesterday and a vendor was demoing how to deal with application tickets by clicking Edit Top 200 Rows in SSMS and just editing values.
I wanted to scream :D
2
u/BlaizeOlle May 21 '26
An overuse of CTE queries I think is a very easy pattern to fall into. CTEs have a lot of great use cases but sometimes I see juniors use it to build some big long chain of transforms because they feel uncomfortable with more fundamental concepts. Again CTEs are great you just don't want to overuse them.
2
u/SweetNecessary3459 May 21 '26
Forgetting WHERE on a DELETE statement. Learned that one the hard way
3
u/czervik_coding May 20 '26
Any developer should know the parts of an execution plan although plugging one into AI seems to be the acceptable method now. Know the difference between clustered and nonclustered indexes. Index on integers whenever possible. Views are good but nested views are not. Use no count, data type properly.
3
u/JEDZBUDYN May 20 '26
Talking about SQL is red flag
2
u/malseraph May 20 '26
Where color.red = 1
2
u/tetsballer May 20 '26
Doing right joins
2
u/jackalsnacks May 20 '26
Dynamic SQL. Niche use cases. If suggested as a solution to a problem, evaluate the rationale and thought process.
1
u/dbxp May 20 '26
See here: https://pragprog.com/titles/bksqla/sql-antipatterns/
The N+1 query problem is probably the most common
1
u/stiggz May 21 '26
and 1=1
there is always a better way
1
u/brunogadaleta May 21 '26
Mixing join X on with join Y where.
1
u/depesz PgDBA May 21 '26
https://wiki.postgresql.org/wiki/Don't_Do_This
1
u/Small_Sundae_4245 May 21 '26
Transactions and checking before committing. It's an interview be extra cautious.
1
u/Shyftzor May 21 '26
For SQL server, unless they are very small, temp tables should be created as actual tables using CREATE TABLE then dropped after. Tables stored in variables use a lot of memory and if they contain large amounts of data can bring the entire db server to a crawl. Also sometimes when a proc.or query is written it runs fine using tables in variables but as the db grows and the datasets get bigger the query will start to run very slow.
1
u/StickPuppet May 21 '26
Order by 1
go straight to hell
1
u/Wise_Mango_5887 May 21 '26
Nested queries. I mean have they heard of cte????
1
u/coltsfan12345 May 22 '26
If given any sort of interpretable questions, make sure to clarify first. Like find the top 10 best salespeople over the last monthā¦. How should we handle ties if there are 3 people tied for 9th? How do we define ābestā? Last month = last 30 days, last calendars month?
Iāll forgive a lot of syntax stuff if I noticed critical thinking.
1
u/Winter_Cabinet_1218 May 22 '26
Multiple nested sub-qureies
Single letter aliasing
Lack of comments
1
u/No_Resolution_9252 May 23 '26
excessive ctes, no regard for readability, non descriptive aliases (as a, as b, as c), reusing aliases in the same script even if out of scope, excessive use of local variables
1
u/TheCuriousEclipse May 24 '26
Subqueries to filter most recent rows over qualify in a more modern system
0
u/jfrazierjr May 21 '26
Seeing the keyword OR and no () in the query. Common rookie mistake.
-3
u/Andfaxle May 20 '26
I think it is important to remember the JOIN semantics and opt for LEFT JOINs instead. For example you want to have the order volume of each customer, so join orders on customers without doing a left join, customers with no orders will be not visible.