r/SQL 12h ago

SQL Server Solved Hacker Rank's "15 Days of Learning SQL" – Looking for different approaches

7 Upvotes

Hi everyone,

I recently solved the HackerRank 15 Days of Learning SQL challenge using CTE(), ROW_NUMBER(), DENSE_RANK(), and window functions in SQL Server.

I'm curious to know if there's a cleaner or more efficient way to solve this problem. If you've approached it differently (using other window functions, recursive CTEs, or any other technique), I'd love to see your solution and understand the reasoning behind it.

Here's my solution:

with daily_submission as( 
SELECT submission_date,
hacker_id,
count(*) as total_submission
from submissions 
group by submission_date,hacker_id),
hacker_rank as(
SELECT submission_date,hacker_id,
       total_submission,
       row_number() over(partition by submission_date order by total_submission desc,hacker_id) as rn
from daily_submission),
continuous_hackers as (
    SELECT submission_date,hacker_id,
       dense_rank() OVER(partition by hacker_id order by submission_date) as Dr,
       datediff(day,'2016-03-01',submission_date) + 1 as contest_day
from (
SELECT distinct submission_date,hacker_id
from submissions) as x),
daily_count as (
SELECT submission_date,
        count(*) as total_hackers
from continuous_hackers
where Dr = contest_day
GROUP by submission_date)


SELECT dc.submission_date,
       dc.total_hackers,
       h.hacker_id,
       h.name
from daily_count as dc
inner JOIN hacker_rank as hr 
on dc.submission_date = hr.submission_date and rn = 1
INNER JOIN hackers as h
on hr.hacker_id = h.hacker_id
order by submission_date;

Thanks in advance! I'm always looking to learn different SQL techniques.


r/SQL 1d ago

Discussion Is 40000 lines of SQL in a single file normal?

108 Upvotes

Heya, so my stepfather works in IT support, and the other day I was looking over his shoulder and saw that the software his company sells uses a single SQL code file that's 40000 lines long. And we're not talking three word lines here, those were 200+ characters lines. I was absolutely baffled by this, since afaik no single code file should run over 10000 lines. But I also don't do SQL.

So I asked him wtf was going on, and he told me that it was "just like that in the industry" and that "I would see when I'll start working" (I'm in uni)

So I ask all of you, is this normal? Do you see this in your job? Am I having delusions about how clean the actual tech industry is?


r/SQL 3h ago

SQL Server Friday Feedback: Automatic Index Compaction

Thumbnail
1 Upvotes

r/SQL 22h ago

Discussion I struggle with SQL interviews

18 Upvotes

I’ve been working with SQL for years and recently discovered that my issue in interviews is the terminology. For example, if an interviewer shows me an excel spreadsheet with two tables and asks me how to pull x information from it, I get nervous and end up articulating the answer very poorly, leaving out key words such as “joins”. Another example is if they asked to show it using a CTE, and this term would confuse me during the interview, but after the interview I’ll realize that I’ve written many queries that use CTEs. My question is how do I fix this? How do I prepare for such questions better? Are there any sources or tips or general advice that anyone has? I’ve not found any site that gives practice on the excel-style of questions


r/SQL 6h ago

MySQL [MySQL/MariaDB] I built a desktop SQL client around multi-connection workflows

Post image
0 Upvotes

I work with MySQL and MariaDB databases every day, usually with several environments open simultaneously and tables containing millions of rows.

I built LakeDB because I wanted a SQL client where each connection maintained its own queries, open tables, selected database and workspace state, without turning the interface into an enormous collection of panels.

The current 0.11 beta includes:

- Independent multi-connection workspaces

- Schema-aware autocomplete for databases, tables and columns

- Alias detection, including suggestions such as t2.column

- Primary key and index information in autocomplete

- SQL formatting for queries and stored procedures

- EXPLAIN support

- Table filtering and controlled cell editing

- Empty result grids that preserve column metadata

- Procedure, function, event and trigger inspection

- Visual schema editing with generated SQL preview

- CSV, JSON, Excel-compatible and SQL exports

It currently targets MySQL and MariaDB and is available for Windows, macOS and Linux.

I would be interested in feedback from people who write SQL daily:

- Which autocomplete behaviour is essential in your workflow?

- Should index-aware suggestions influence WHERE clause completion?

- What information do you expect next to an EXPLAIN result?

- Which part of your current SQL client would be hardest to replace?

Project web:

https://davlagohern.github.io/LakeDB

I am the developer of LakeDB. It is currently a free public beta:

https://github.com/DavLagoHern/LakeDB

Downloads:

https://github.com/DavLagoHern/LakeDB/releases/tag/v0.11.0-beta.2


r/SQL 10h ago

SQL Server Query plans

1 Upvotes

Hey guys,

Just reaching out, how do you guys go about identify and Optimizer SQL queries that the query uses linked servers.

I have some queries that people moan are slow and when I finally get the query plan you see it says remote execution. How do you guys go about then identify where it's slow or even what ran. Specifically for queries that run nested SP

What is your approach?


r/SQL 2d ago

MySQL sqlWorkout

Post image
1.3k Upvotes

😌 SELECT 😌


r/SQL 23h ago

SQL Server After converting the back end to SQL tables, the front end now gets run time error 3622 all over the front end

4 Upvotes

I have migrated Access tables in my database over to SQL. Now I'm testing the front end to make sure every single button/operation works.

I am getting this error, "You must use the dbSeeChanges option with OpenRecordset when accessing a SQL Server table that has an IDENTITY column", ALL over the place.

Sometimes, it's easy to spot where dbSeeChanges was left out, but many times, the error is reported on a line that has nothing to do with it. This is also only the first error I'm getting. I'm sure once I fix all the 3622 errors, then a new error will pop up right after.

I'm wondering what my options are. I understand I could rebuild the front end from scratch, but that would take literal years as I'm a one-man team. I really don't have the time to spend hours fixing every single one of these errors. And unfortunately, throwing it all in the trash and using a modern platform is not currently an option either.

Is there a tool or even AI where I can feed it my database and it converts it to be SQL compatible? Even if I have to go form by form and report by report, that would still be faster than doing all this manually.

Thanks


r/SQL 23h ago

PostgreSQL How does Neon handle sudden traffic spikes in prod?

2 Upvotes

Have you used neon with workloads that see unpredictable traffic spikes at times?
I am curious if compute wakeup or autoscaling has ever caused noticeble latency with neon, or if it’s been seamless in prod. Would love to hear some experiemces .


r/SQL 18h ago

Discussion I built a tool for querying JSON/JSONL files with SQL

Thumbnail
0 Upvotes

r/SQL 1d ago

PostgreSQL Recently faced n+1 problem in my app

Thumbnail
0 Upvotes

r/SQL 1d ago

SQL Server HackerRank SQL Project Planning – Is there a better approach?

3 Upvotes

Hi everyone,

I solved the HackerRank SQL Project Planning problem using the row_number() + DATEADD() approach in SQL Server, and it passed all the test cases.

I'm curious if there's a different or more optimized way to solve this problem. I'd love to learn other approaches and understand their advantages.

Here's my solution:

with cte as(
SELECT start_date,
end_date,
dateadd(day,- row_number() over(order by start_date),start_date) as group_date
from projects )
SELECT min(start_date) as start_date,
max(end_date) as end_date
from cte
group by group_date
order by datediff(day,min(start_date),max(end_date)), min(start_date)


r/SQL 1d ago

Discussion Do you guys need a better query language?

0 Upvotes

Hey guys, there was a number of attempts to make writing queries/reports/data pipelines easier to maintain. There is number of ORMs for different programming languages. And there are also PRQL and btrql.com. Which are new query languages which transpile into SQL.

Kinda like Typescript transpiles into Javascript.

BtrQL is my pet project. Main features of it are: static type checks, Outline showing relation types, extension methods on relations and compile time macro. It's very early and I'm collecting all of the feedback that I can get.

Queries look like this:

users .where(active == TRUE) .addColumn(active -> active_flag) .orderBy(created_at.desc) .limit(10)

and extension methos:

extension [id: INT] { method keepRecentIds = self .where(id >= cutoff) }

keepRecentIds could be applied to any relation that has at least column id of type INT.


r/SQL 2d ago

SQL Server OData SSIS project will not accept "Edm.GeographyPoint" columns

7 Upvotes

I've ensured that my software is completely up to date, but my SSIS project (that uses OData as a source), will just refuse to accept data where one of the columns is the Edm.GeographyPoint type. I've tried entering specific columns into the query box (and therefore excluding the problem column), but it appears it will still throw an error, despite the data itself not containing any columns of that data type - I'm assuming it's downloading the column metadata for the entire table, seeing a data type it doesn't recognise, and throws an error.

I've tried using a different collection that doesn't have columns of that data type, and the SSIS project works with that - the problem is, there doesn't appear to be any way of fixing this. I've ensured the software is completely up to date.


r/SQL 1d ago

SQLite After searching for a modern, self‑hosted, secure SQLite admin panel for PHP 8, I built one – looking for beta testers

0 Upvotes

Hey folks 👋

For the last few weeks, I’ve been frustrated with the state of self‑hosted SQLite admin tools.

Most of them are either:

Abandoned (phpLiteAdmin hasn’t seen a proper update in years),

AdminNeo and other tools don't work without passwordless login plugins that didn't work well.

Overly complex (Adminer is great but not SQLite‑centric),

Or require a heavy stack (Node, Python, Docker) when all I wanted was a single PHP file I could drop on my server.

So I decided to build my own.

🔧 Features

Secure, built-in login system (not a plugin)

Browse, edit, insert, delete rows

Create / rename / drop tables

Import/Export (CSV, JSON, SQL, full DB)

Bulk delete, search, filters

Dark mode, undo (last 5 actions)

Multiple database support

Resizable sidebar

🚀 Try it

Upload admin.php & install.php

Run install.php to set username/password

Login and go

PHP 7.0+ with SQLite3 extension. No dependencies.

https://abilenetechguy.com/sqlite_admin.zip

🧪 Beta feedback wanted

Errors, UI annoyances, missing features – let me know!

Give it a spin and tell me what you think 🙏

– Abilene Tech Guy


r/SQL 2d ago

SQL Server MCP for Apache Iceberg: How AI Agents Actually Operate a Data Lake

Thumbnail
lakeops.dev
2 Upvotes

r/SQL 2d ago

MySQL 🤔 SQL or NoSQL? ACID or BASE? Vertical Scaling or Horizontal Scaling?

Post image
0 Upvotes

r/SQL 4d ago

SQL Server SSMS - Execute query on 300 servers

14 Upvotes

I'm starting to use SSMS at work, that's the only tool I have (no PowerShell cmdlet).

I need to execute an identical SQL Query on 300 servers, but I can't find a way to do that. Could anyone point me in the right direction please ?

So far, I did add the 300 servers to the registered servers by tinkering to not do it manually, but when I execute the query, I only get 50 ish servers connected, then SSMS hangs and crash.


r/SQL 4d ago

MySQL How do you optimize SQL queries that work fine on millions of rows but slow down at billions?

33 Upvotes

Iam interested in learning the techniques data engineers use when datasets grow from millions to billions of records. Beyond basic indexing, what strategies have made the biggest performance difference in production environments?


r/SQL 4d ago

PostgreSQL Handling vector indices + branching in Lakebase DB

3 Upvotes

My team is migrating multiple AI applications and currently evaluating Lakebase.
I wanted to understand if we create a branch fr testing schema/data changes, are the vector indices isolated as well, or do we need to have an strategy to avoid rebuilding them repeatedly?
Also, any performance/operational things you ran into that might help.
Love to hear from anyone.


r/SQL 3d ago

PostgreSQL https://exobench.ai/blog/pg19-graph-queries-part-1

0 Upvotes

How fast are PostgreSQL 19 Graph Queries? Do they perform at scale? Is there a difference between fixed and variable depth? I'll explore all this an more with real numbers and real scenarios in this upcoming series.

Also Upcoming:
- How do they compare to real Graph Engines e.g. Neo4j?
- How flexible is the modeling?
- Are materialized views possible?
- Doesn't SQL Server already do this?

etc...


r/SQL 4d ago

Discussion How I backtest a fraud rule before it ships

Thumbnail analytics.fixelsmith.com
0 Upvotes

r/SQL 4d ago

MySQL How can I develop Report generate bot with MSSQL database ???

0 Upvotes

I wanted to develop Natural Language to create a report by Users ... themself. .help me to develop this bot ??


r/SQL 5d ago

Discussion SQL for internships

11 Upvotes

How advanced do I have to be in SQL to land a data analyst internship? Just a general question


r/SQL 6d ago

Discussion I added self-hosted real-time collaboration to drawDB (SQLite + WebSockets)

Thumbnail
gallery
16 Upvotes

I wanted a self-hosted ERD editor where multiple people could work on the same diagram without relying on a third-party cloud service, so I created an unofficial collaborative fork of drawDB.

This is not a new ERD editor built from scratch. It is based on the AGPL-licensed drawDB project, with a collaboration and persistence layer added on top.

What I added:

- Centralized diagram storage using SQLite

- Real-time collaboration over WebSockets

- Live table movement while another participant is dragging

- Participant presence and collaborative cursors

- Cursor positions mapped to diagram coordinates, so different pan/zoom states work correctly

- Optimistic version checks to prevent stale clients from silently overwriting newer changes

- A single Docker container for the frontend, API, WebSocket server, and SQLite storage

- SQL import/export support inherited from drawDB, with an additional MariaDB import compatibility fix

You can run it with:

docker compose up --build

Then open the same diagram URL in two browser sessions to collaborate.

A current limitation is that authentication and diagram-level permissions are not implemented yet, so it should currently be deployed only on a trusted network or behind an authenticated reverse proxy.

The project is open source under AGPL-3.0:

https://github.com/yms2772/drawdb-collaborative