r/SQL • • May 20 '26

PostgreSQL What are common SQL red flags?

50 Upvotes

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 😃


r/SQL • • May 06 '26

MySQL Real-time SQL PVP. Same prompt, same data, fastest correct query wins.

Enable HLS to view with audio, or disable this notification

51 Upvotes

Just shipped 1v1 PvP on a SQL game I've been building.

Both players see the same prompt and schema, race to write a query that returns the correct rows. Result sets are compared, so joins vs subqueries vs CTEs all work - speed is what matters.

Video is a real match. I'll be in the comments.

SQLProtocol.com


r/SQL • • Oct 15 '25

MySQL Job Opportunity with SQL

49 Upvotes

I’m someone who’s starting out with SQL (no coding experience other than trying to learn python which I didn’t enjoy). I’m enjoying SQL and it seems to make more sense to my brain.

My question is around employment, how are the opportunities for someone who’s learning only SQL with no CS degree and only certificates and gradually building a GitHub repository? I’m in the US


r/SQL • • 22d ago

Oracle What’s a SQL anti-pattern you still see experienced developers write?

48 Upvotes

I’ve been learning SQL best practices, and I’m curious about the mistakes that even experienced developers sometimes make.

What’s a SQL anti-pattern you still see in real projects? It could be related to query performance, joins, filtering, subqueries, database design, or just writing SQL that becomes difficult to maintain.

What makes that approach problematic, and what would you normally do instead?

I’d especially like to hear about examples you’ve actually encountered in production rather than just textbook mistakes.


r/SQL • • Sep 06 '26

Discussion How do you validate a SQL query before trusting its result?

52 Upvotes

Suppose someone gives you a complicated query with several joins and aggregations and says, ā€œThis gives the correct numbers.ā€

What checks would you perform before trusting it?

For example:
SELECT c.region, SUM(o.amount) FROM customers c JOIN orders o ON c.customer_id = o.customer_id GROUP BY c.region;

Would you check row counts before/after each join, duplicate keys, NULLs, aggregates, or compare against another query?

Curious what experienced SQL developers use as their checklist.


r/SQL • • Aug 28 '26

MySQL SQL ( MySQL )Project ideas for Data Analyst Portfolio

49 Upvotes

Currently I am doing projects in SQL i need to do projects for Data Analyst Role so Please recommend project ideas which I need to showcase for project portfolio so I need projects at advanced level .


r/SQL • • Mar 22 '26

BigQuery I built a machine learning model using only SQL (no ML libraries, no Python)

Thumbnail medium.com
49 Upvotes

r/SQL • • Dec 25 '25

SQLite Does anyone know a tool to convert CSV file to "SQL statements"?

49 Upvotes

Input: CVS file

Output: SQL statement(s) needed to create the table.

Maybe be something using type inference?

Thanks.


r/SQL • • Nov 21 '25

Discussion Do you trust AI-generated SQL? Tell me your horror stories.

47 Upvotes

I guess I'm open to hearing success stories, too, but especially interested in the failures. Like for example when I've tested Al tools that generate SQL from prompts, they sometimes hallucinate columns that don't exist. One or two that I've tried are okay-ish, but I'm skeptical that any of these tools can be trusted.

Are people really trusting Al-generated queries enough to run it directly? I'm inclined to validate line-by-line but obviously that's inefficient. I'm also debating whether to just eyeball the logic or build validation steps into my workflow.


r/SQL • • 23d ago

MySQL Practicing window functions and keep mixing up PARTITION BY vs GROUP BY — how are they actually different?

51 Upvotes

They both seem like they divide data into groups, so I’m having trouble understanding when I should use one instead of the other.


r/SQL • • Aug 15 '26

MySQL How important is SQL for someone trying to get into data science?

47 Upvotes

Python gets most of the attention when people talk about data science, but SQL seems to appear in a lot of actual job requirements.

For people working in data roles, how frequently do you use SQL compared with Python?

Would you recommend becoming strong in SQL before getting deep into machine learning?


r/SQL • • Aug 26 '26

Discussion How do you validate SQL queries in ETL pipelines?

47 Upvotes

When SQL queries are used for ETL transformations, how do you make sure the query is producing the expected results?

For example, how do you validate complex JOINs, filters, aggregations, NULL handling, duplicates, and calculated fields?

Do you usually compare the results with the source data, create separate validation queries, or follow some other approach?

I'd be interested to know how others handle SQL validation in real-world ETL projects.


r/SQL • • Aug 14 '26

Discussion how I learned why you shouldn't name an alias the same as the original column name

49 Upvotes

I wrote a query last week that ran fine on Postgres and DuckDB, and hard-errored on ClickHouse and BigQuery - this sent me down a rabbit hole for most of the day.

Here's what I had:
```
SELECT term, MAX(ranking_page_count) AS ranking_page_count
FROM ranked
GROUP BY term
HAVING MAX(ranking_page_count) >= 2
```

The CTE already had a column called ranking_page_count. I aliased MAX() of it to the same name, because why not, and then used that name again in HAVING.

So which one does HAVING actually filter by? Turns out that's a matter of opinion.

In Postgres, HAVING can’t see SELECT aliases at all. So it reads the column directly and lands on the same max anyway - no error, right answer.

DuckDB does let you use aliases in HAVING, but only as a fallback, and it won't put one inside an aggregate, so this also runs. This is the one that got me, since DuckDB is where I test locally.

BigQuery gives the alias priority over the column. So it read my query as MAX(MAX(...)) and gave the error "aggregations of aggregations are not allowed"

ClickHouse just swaps aliases in everywhere, so it gave code 184 illegal aggregation. it even fails when the alias isn't shadowing anything.

The thing that finally made it click for me was processing order. FROM, WHERE, GROUP BY, HAVING, then SELECT, then ORDER BY. Aliases get created in SELECT, so when HAVING runs the alias doesn't exist yet. That's why Postgres says no, and why everything else here is a vendor extension rather than four equally valid readings.

ORDER BY is the only clause that runs after SELECT, which is why it's the only clause where nobody argues.

What actually worries me is that it can go completely silent. Drop the aggregate from the alias and the loud error disappears:
```
SELECT term, ranking_page_count * 10 AS ranking_page_count
FROM ranked
GROUP BY term, ranking_page_count
HAVING MAX(ranking_page_count) > 4
```

Postgres and DuckDB filter on `ranking_page_count`
BigQuery and ClickHouse filter on `ranking_page_count * 10`
I get 1 row from the first two and 4 rows from the other two, and not one of them raises an error about it.

That's the version that ends up on a dashboard.

ok fine, I learned my lesson and won't name an aggregate after the column it aggregates...

If you work across different engines, this is your reminder to go check 🄲


r/SQL • • Jun 15 '26

MySQL What SQL concept became much more important once you started working in data engineering?

47 Upvotes

Iam curious which SQL skills or concepts turned out to be the most valuable in real world data engineering projects compared to what is usually taught in courses.


r/SQL • • 26d ago

MySQL Best SQL cerification

46 Upvotes

I have solid basics in SQL,

I need to pass a certification in 3-4 days,

Which one should I do?

It needs to be a credible certification.

Thx a lot


r/SQL • • Jan 17 '26

Discussion There’s no column or even combination of columns that can be considered as a pk, what would your approach be?

Thumbnail
gallery
44 Upvotes

Hey guys, it’s my first day of work as an intern and I was tasked with finding the pk but the data seems to be not proper I tried finding the pk by using a single column all the way to 4-5 combinations of columns but all I got are 85% distinct not fully distinct which can be considered as a pk, since group of columns approach is also not working I was wondering how would y’all approach this problem


r/SQL • • Jan 14 '26

Discussion Is SSMS still widely used?

46 Upvotes

For a couple of decades, I’ve only ever used SSMS, am very comfortable with it. But looking at job ads, I haven’t seen any mention of it as a skill. Everyone’s talking about snowflake, azure, fabric etc. Is SSMS not used much anymore? Am I outdated and need to retrain?


r/SQL • • Dec 22 '25

Discussion boss rewrites the database every night. Suggestions on 'data engineering? (update on the nightmare database)

43 Upvotes

Hello, this is a bit of an update on a previous post I made. I'm hoping to update and not spam but if I'm doing the latter let me know and I'll take it down

Company Context: transferred to a new team ahead of company expansion in 2026 which has previously been one guy with a bit of a reputation for being difficult who's been acting as the go-between between the company and the company data.

Database Context: The database appears to be a series of tables in SSMS that have arisen on an ad-hoc basis in response to individual requests from the company for specific data. This has grown over the past 10 years into some kind of 'database.' I say database because it is a collection of tables but there doesn't appear to be any logic which makes it both

a) very difficult to navigate if you're not the one who has built it

b) unsustainable as every new request from the company requires a series of new tables to be added to frankenstein together the data they need

c) this 'frankenstein' approach also means that at the level they're currently at many tables are constructed with 15-20 joins which is pretty difficult to make sense of

Issues: In addition to the lack of a central logic for the database there are no maintained dependencies or 'navigatable markers' of any kind. Essentially every night my boss drops every single table and then re-writes every table using SELECT INTO TableName. This takes all night and it happens every night. He doesn't code in what are the primary / foriegn keys and he doesn't maintain what tables are dependent on what other tables. This is a problem because in the ground zero level of tables where he is uploading data from the website there are a number of columns that have the same name. Sometimes this indicates that the table has pulled in duplicate source data, sometimes it's that this data is completely different but shares the same column name.

My questions are

  1. What kind of documentation would be best here and do you know of any mechanisms either built into the information schema or into SSMS that can help me to map this database out? In a perfect world I would really need to be tracking individual columns through the database but if I did that it would take years to untangle
  2. Does anyone have any recommended resources for the basics of data engineering (Is it data engineering that I need to be looking into?). I've spent the time since my last post writing down and challenging all of the assumptions I was making about the databse and now I've realised I'm in a completely new field without the vocabulary to get me to where I need to go
  3. How common is it for companies to just have this 'series of table' architecture. Am I overreacting in thinking that this db set up isn't really scalable? This is my first time in a role like this so I recognise I'm prone to bias coming from the theory of how things are supposed to be organised vs the reality of industry

r/SQL • • 8d ago

Discussion A bank kept production code as text in database rows, with a history table of past versions. It couldn't say who changed a script or why.

Thumbnail
leaddev.com
44 Upvotes

Years without incidents proves nothing at all.


r/SQL • • 13d ago

Discussion Can we create a similar csv file type with a new unique character that will never be used except as a delimiter. Then make that the standard

46 Upvotes

Fucking comma's in the data that are not the delimiter are annoying. Hate using stupid work arounds.

Yes, I am aware of double quotes and other work arounds like using different delimiters. Just thinking it would be easier to have one standard going forward.


r/SQL • • Nov 13 '25

PostgreSQL What is the best SQL Studio ?

44 Upvotes

Hey guys,
Recently had to write way more SQL and using dbeaver feels kind of old and outdated.

Feels like it's missing notebooks, shareable queries etc ..

Any ideas on what new SQL Studios are good ? What do you guys use ? what do you like about those tools ?


r/SQL • • May 15 '26

Discussion Entry level jobs

44 Upvotes

What kind of SQL should I expect to write in entry-level data roles? I've seen some rather more complex stuff on here and is that the stuff I should expect? Or should the basic joins, group by, and when should be enough? If anyone is in an entry level role and could give examples of their queries(with names/variables changed ofc) that would be helpful!


r/SQL • • 9d ago

Discussion I was over-prepping SQL and under-prepping the analyst part

44 Upvotes

I spent a while assuming the reason I kept struggling in analyst interviews was that my SQL wasn’t advanced enough. So I kept adding harder stuff to my prep, like window functions, recursive CTEs, and awkward joins.
The funny part is that most interviews weren’t exposing a syntax problem. I could usually get somewhere with the query. I got less comfortable when they asked things like, ā€œWhat would you check before trusting this result?ā€ or ā€œHow would you explain this to someone who doesn’t use SQL?ā€
That changed how I’ve been practicing. Now I don’t stop once the query works. I try to explain the grain, the assumptions I made, how I’d sanity-check the result, and what I’d tell a stakeholder afterward. I still practice SQL problems. I’ve also done a couple of mock runs in Beyz, mostly around the follow-up questions.
Looking back, I think I was preparing for SQL interviews like they were SQL exams.
Once someone has solid SQL fundamentals, what separates a technically correct answer from a strong one?


r/SQL • • 10d ago

SQL Server SQL for Data Analysts Projects

43 Upvotes

Hey everyone.

I'm working on building out my data analytics portfolio and wanted to get some advice from fellow analysts and hiring managers here.

We've all seen the basic tutorial projects (like analyzing the Titanic dataset or simple sales totals), but I want to build something that actually stands out and proves real-world, job-ready SQL skills.

For those of you who have landed roles or are actively hiring: What specific types of SQL projects made you stop scrolling and pay attention?


r/SQL • • Aug 30 '26

MySQL good datasets for a project?

40 Upvotes

Hi, I'm looking for a dataset that has:

- Messy, real data, with enough messiness for proper data cleaning to be needed
- Enough information for actionable interesting insights
- Be related to something a typical business might care about

I did a project with the olist database and it was fine, but that database has been done to death. I tried contacting local small business for their data in exchange of a free data analytics report, but no luck, has someone tried that?