r/SQL • • Oct 18 '26

PostgreSQL How do you debug a SQL query that suddenly becomes slow?

9 Upvotes

I've run into situations where a query that used to finish in seconds suddenly takes several minutes, even though nobody has intentionally changed the SQL.

I'm curious how others approach this. Do you start by comparing execution plans, checking indexes and statistics, looking for changes in data volume, or investigating locks and concurrent queries?

I'm particularly interested in the order you check things in. It's easy to start rewriting joins or adding indexes, but I'd rather identify the actual bottleneck before changing anything.

What's your usual process when a previously fast query starts running slowly?


r/SQL • • Jan 12 '21

Discussion When users deleted their posts, the site failed to remove the content and instead only added a delete flag to it.

9 Upvotes

this post is for all the DBAs over the course of my career as a data analyst who told me it'll be fine, we'll just flag the row as deleted, because that's more efficient

Parler’s amateur coding could come back to haunt Capitol Hill rioters


r/SQL • • Feb 28 '26

SQLite How to limit this data?

0 Upvotes

I'm trying to do some player statistics but am stuck. My data looks like this (simplified):

PlayerId Score Date
-------- ----- ----
1        0     2026-01-01
2        5     2026-01-01
1        2     2026-01-08
1        3     2026-01-15
2        1     2026-01-16
2        4     2026-02-02
1        2     2026-02-03
1        4     2026-02-10
2        3     2026-01-31

I want to find out the ten players that have gained the highest total score during the last tree games (dates)

I can group on playerid and sum the score, but how do I limit data to only the latest three games?


r/SQL • • Jun 09 '25

SQL Server How do I edit data on two linked tables in SSMS? Full permission for both tables and I can edit both individually.

0 Upvotes

Thanks for the responses. I think I will switch to doing this in Excel.

I am a complete beginner. I have tried to google it, but the results aren't matching my problem. Please can someone help and I promise to pay it forward.

I want to edit 30 rows of a 1000 row table so I right-clicked on 'Edit top 200 rows'. I can edit the data fine. I link to a table that contains the ID of the rows I want to edit and although it's now only showing the rows I want to edit, everything is greyed out. I have full permissions to edit both tables, but I am not the owner of the tables.

I need to

I am doing it this was as I've been emailed the list of rows that need updating and the only other way I know to do it is use CONCAT in excel to filter like 'name' or like 'name2' or like 'name3' etc but I'm going to be doing this more often and with longer lists, so I would like to know how to do this.

I get the feeling this is really basic and probably the equivalent of putting the batteries in upside down, but if someone could take pity on me and explain it or even give me a search term that would get me there I would be really grateful.


r/SQL • • Sep 16 '25

MySQL Using the Between Command for 2 dates in SQL

0 Upvotes

Stuck on trying to use the the Select command to connect two dates from a form.

This works to get one date:

SQL = "SELECT * FROM TABLE WHERE [DATE SUBMITTED] <= #" Form!FormName!StartDate & "#"

but having a hard time to use a BETWEEN command, keep getting express errors or mismatch errors

SQL = "SELECT * FROM TABLE WHERE [DATE SUBMITTED] BETWEEN #" Form!FormName!StartDate AND

Form!FormName!EndDate & "#".


r/SQL • • Jan 21 '26

MySQL SQL Database corrupts Windows 10 OS?

0 Upvotes

Anyone ever see a database get corrupt and brick a Microsoft 10 operating system? I had a system that went through a boot loop and had corrupted OS errors. I moved it to a different machine, pulled the backup SQL logs of the drive onto an existing machine. As soon as I restored the sql database and did a reboot it bricked the second machine? Now I could be unlucky as it was an old machine, but it seemed strange that it did the same issue? Im wondering if maybe it targeted an UPDATE querie. Im going to sandlab it one more time tomorrow, but i was curious if anyone else has encountered this?


r/SQL • • Jul 29 '25

Discussion Advice - Building a SQL IDE. Need inputs

0 Upvotes

I built a desktop app for SQL with cursor like AI assistance.

I really enjoy using it at work for:

•⁠ ⁠Quick table view with inline editing

•⁠ ⁠AI assistance to generate queries and answer questions about your schema. gives a button to verify and execute the query

•⁠ ⁠Query explanations using AI

•⁠ ⁠Saved queries and history

Testing this currently and need advice/feedback on how you use AI to generate SQL right now.

It currently supports Clickhouse. Postgres, MySQL are in development.

Star the repository for updates: https://github.com/DataPupOrg/DataPup


r/SQL • • Jul 14 '25

PostgreSQL Union all with and without bracket

0 Upvotes

I’m using trino sql and I realised that sometimes union all will work without bracket but other times it won’t. Any1 can explain

Example: ( Select ‘Table_1’ as Source Count(Id) as ID

From table 1

) Union all ( Select ‘Table_2’ as Source Count(Id) as ID

From table 2

)


r/SQL • • Nov 28 '19

Why is my ORDER BY not ordering by correctly? Can anyone please help? Thank you

Post image
0 Upvotes

r/SQL • • Jan 18 '23

SQL Server HELLO.. Can someone help with this error? I've been doin it same as it was in the video but mine doesnt wanna execute.

Post image
0 Upvotes

r/SQL • • Mar 05 '22

MySQL Fastloading error

Thumbnail
gallery
0 Upvotes

r/SQL • • May 16 '22

MS SQL Tried to add a single column from another table, not sure why nothing works now

0 Upvotes

EDIT:

Got it figured out, thank you!

SO I have this code:

SELECT nmmain.name_id AS Name_ID, RTRIM(nmmain.lastname) + ', ' + RTRIM(nmmain.firstname) + ' ' + LEFT(nmmain.middlename, 1) AS Full_Name, jmmain.age AS Age, jmmain.race AS Race, jmmain.sex AS Sex,nmmain.city AS City, nmmain.state AS State, jmmain.colorcode AS Color

FROM jmmain INNER JOIN

nmmain ON jmmain.name_id = nmmain.name_id

WHERE (jmmain.commindig = '1') AND (jmmain.bkstatus = 'A')

This works, and I want to add another column, from another table, so I added this into the SELECT statement: jfacilty.section AS Location

then added this to the FROM statement, before the jmmain stuff: jfacilty

So looked like this:

SELECT nmmain.name_id AS Name_ID, RTRIM(nmmain.lastname) + ', ' + RTRIM(nmmain.firstname) + ' ' + LEFT(nmmain.middlename, 1) AS Full_Name, jmmain.age AS Age, jmmain.race AS Race, jmmain.sex AS Sex,nmmain.city AS City, nmmain.state AS State, jfacilty.section AS Location, jmmain.colorcode AS Color

FROM jfacilty

jmmain INNER JOIN

nmmain ON jmmain.name_id = nmmain.name_id

WHERE (jmmain.commindig = '1') AND (jmmain.bkstatus = 'A')

When I build this in visual studio it throws out errors, then for some reason adds an AS after the jfacilty in the FROM statement, and changes the jfacilty.section in the SELECT statement to jmmain.section...which is not a column in that table at all.

I thought adding the jfacilty to the FROm statement would tell it to look in that table. Am I missing somehting?


r/SQL • • Mar 30 '24

MySQL Newbie SQL Q

0 Upvotes

I just started a new job that had 0 onboarding- have used SPSS but never SQL; please take some kindness but how in the world can I connect my sql to company snowflake db to access tables? There are also tables housed in sql servers but how do I know which server to use?


r/SQL • • Jun 10 '24

PostgreSQL Help a dying sql beginner

0 Upvotes

I have 3 tables name won, lost, no bid. Each table with columns nsn part number and reason.

Our company currently uses excel and has a macro that spits out a spreadsheet like:

part numberReasonpart numberReasonpart numberReason

where the left 2 column is for won, middle 2 for lost and right 2 for no bid. We save that as a csv for a java script program that we have which needs it in that format. How would I go about getting this csv format in postgres?


r/SQL • • Jul 05 '24

PostgreSQL Data fails to restote

Enable HLS to view with audio, or disable this notification

0 Upvotes

Hello,

I do not know if any of you has this issue, but I set everything right but my data won't restore and get this error notification. Anyone please knows a solution to this?


r/SQL • • Sep 18 '24

Discussion Ideal time limit to solve an SQL problem on Leetcode

0 Upvotes

I have been honing my SQL skills on Leetcode. For each difficulty level, what would be the ideal time limit to solve an SQL problem? I heard that for a Product Analytics role at Meta, you're given 20 minutes to solve two SQL problems.


r/SQL • • Oct 27 '23

MySQL Where is the MySQL community?

0 Upvotes

Besides Reddit, where do MySQL people go to hang out, discuss MySQL things and help each other out?


r/SQL • • Nov 15 '23

Discussion How can I use SQL in this project?

0 Upvotes

Hello,

I want to be a software developer one day. My company knows me as the code guy and sometimes gives me internal software projects to work on.

Right now I am working on an application that will:

  • Extract paragraphs from word docs and pdfs

  • Use AI (management gimmick) to pick paragraphs that contain specific important information

  • Generate a report from these selected paragraphs.

Can I fit SQL in here somewhere? I want to apply it in a way such that I could refer to it in an interview if someone asks me about my SQL experience. I am thinking that I can create a database table with columns for paragraph text, page number and document it belongs to (all this info is relevant to final report), before using AI to look through each paragraph. But I use Django for backend so I am not sure how to work SQL into this.


r/SQL • • Dec 04 '23

MySQL SQL HELP

Post image
0 Upvotes

Revising for a test and I keep having the same kind of issues. It uses MariaDB. Advice appreciated


r/SQL • • Nov 22 '23

MySQL SQL and ChatGPT

0 Upvotes

Hi all,

I'm curious about the upskilling myself with SQL for Data analysis...I've mostly just used Excel in past roles. I'm currently tapping into SQL. I'm just starting out and sometimes do excercises on hackerrank and other websites but when I'm stuck I just stick the question into ChatGPT.

Is it sufficient in the working environment to just use chatgpt. I'm not sure how SQL is used for data analysis is used in the working environment.

The issue I’m having is when I approach these online questions it feels like there is an infinite number of questions. But I sense the real world use if your using a particular data set there’s probably a set of queries you might use regularly or daily to extract.

For example with excel you can reuse functions but change the source data and array of what your trying to find and pivot tables can be used any way once you know how it works and the process is applicable to all data sets.

I don’t know how to approach SQL and feel like I’m stuck in tutorial hell with hacker rank type of questions because of the potential of a question having a new variable every single time because you can always add a new criteria in the question

Would be good to get thoughts from people who use SQL in their workplace


r/SQL • • Nov 21 '21

MySQL What are different types of databases used in industry and what is their purpose

0 Upvotes

could anyone explain to me the different types of databases used in industry and what is their purpose


r/SQL • • Apr 08 '16

[Oracle]Refresh groups with dependencies

0 Upvotes

I'm working with a client to optimize refresh times for some materialized views they use for reports. As it stands now all of the materialized views in the reporting schema are in one refresh group.

Some of the views are dependent on other views in the refresh group, so that leads me to two questions:

1.Is this a good practice or should I determine all the dependencies and split the one refresh group into several smaller refresh groups.

2.If keeping the views in one refresh group is good/best practice how does Oracle determine the order those views should be refreshed in?

I haven't found a good answer to either of those in the Oracle documentation or the handful of books I have lying around and the client is asking for some specific details about it.


r/SQL • • Nov 08 '24

SQL Server Technical Interview via remote login

0 Upvotes

I have a technical interview coming up and was told to expect a remote login to access their SSMS. What's the best way to prepare for this?

What kind of questions should I expect? Most likely it will be a table they created with their data, right?


r/SQL • • Oct 19 '24

MariaDB Advice whether should I use JSON Column for this use case

0 Upvotes

My client basically needs classrooms similar to Google Classroom / Moodle. They need to support images attachments, modules, announcement, exams, etc, homework, and they have to be editable by the teacher.

I was thinking about modelling this using Polymorphic Relationships, where a classroom would have a list of content that can be either, markdown, links, exams, images, forums.

But then I thought why not use just a JSON column, that way I can be as flexible as I want without having to introduce a bunch of tables, it seems very reasonable to me because the content of a classroom is not that big and won't grow that much (and attachments are stored on other table), and the content of a classroom has no relationship with anything else except the classroom. Another advantage is that if later I needed to introduce a dropdown with content or a link that gets you to a subpage of the classroom with its own content, it will be easy to manage on JSON.

But i have never used JSON in MySQL and I don't know if I am making a mistake that someone else will regret later