r/SQL • • 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 😃

49 Upvotes

192 comments sorted by

View all comments

Show parent comment

1

u/techforallseasons May 21 '26

Some of use use alot of schemas, so tables in the same query but are from different schema may have name collisions and sometimes the schema.table.column syntax itself gets too long.

We ALWAYS alias as a rule, even for single table queries, and we use names that are somewhat consistent for the same tables.

This is a made up example, so excuse the poor choices - it is to make the object more obvious:

SELECT
     student.name
     ,staff.name
FROM
     classroom.members class
JOIN
     people.students student
     ON
     student.id = class.student_id
JOIN
     people.instructors staff
     ON
     staff.id = class.staff_id
WHERE
    class.year = 2026
AND
    class.term = 'Spring'
ORDER BY
     staff.name
 ,student.name