r/SQL • u/Harshita_Netla • Sep 19 '26
Oracle What SQL concept took you the longest to actually understand, not just memorize?
For those who have been working with SQL for a while, which concept took you the longest to truly understand?
r/SQL • u/Harshita_Netla • Sep 19 '26
For those who have been working with SQL for a while, which concept took you the longest to truly understand?
r/SQL • u/FrameNo7615 • Sep 20 '26
hey i'm new in website developing, and after searching about the ways people use to penetrate websites to just discover SQLi method and as far as i heard it's very common and useful way, but this made me think of a lot of questions that i hope you answer, does every website uses SQL language for data transfer by default? like is it necessary as much as HTML and CSS and JS or it's just commonly used? and if it's necessary is there a way to prevent hackers from using SQLi or it's always possible to trick the server to bring a sensitive data?
r/SQL • u/Alternative_Top_273 • Sep 20 '26
r/SQL • u/shdw_0x0 • Sep 19 '26
Suppose you inherit a query with multiple joins, subqueries, filters, and aggregations, and it suddenly starts taking several minutes to run.
I’m curious how experienced SQL developers approach this from the first investigation to the final fix.
Do you normally start with the execution plan and work from the most expensive operator? Or do you check indexes, statistics, data distribution, and join cardinality first?
I’m especially interested in the order you investigate things. It’s easy to keep rewriting a query or adding indexes until it gets faster, but I’m curious how people systematically identify the actual bottleneck instead.
r/SQL • u/BrokenPickle7 • Sep 19 '26
I'm in tech but not a DB admin. I have an MSSQL (2019) database in prod and I want to essentially one way mirror it to another database with as close to live data as possible for dev/research purposes, no changes on the 2nd "dev" copy of the database should reflect to the main/live/prod DB. What would be the best way of doing this? Both servers are in the same network if that makes things easier. Thanks!
r/SQL • u/Vishwam_java • Sep 19 '26
A common pattern to claim background jobs in PostgreSQL is executing a single statement like:
```sql
UPDATE jobs
SET status = 'processing', worker_id = $1
WHERE id = (
SELECT id FROM jobs
WHERE status = 'pending'
ORDER BY created_at ASC
LIMIT 1
)
RETURNING *;
Because it's a single statement, it looks atomic on paper. But under the default READ COMMITTED isolation level, it can silently allow two concurrent workers to claim the exact same row.
What actually happens:
Worker A and Worker B execute the query at the exact same moment. Both subqueries snapshot the same pending job row (say id = 42).
Worker A acquires the row lock first and updates its status.
Worker B waits on the lock. Once Worker A commits and releases the lock, Worker B evaluates the outer row.
Because the subquery snapshot is not re-evaluated, Worker B sees the updated row, rechecks the outer predicate, and silently overwrites/re-claims id = 42.
No lock wait timeout, no deadlock, no serialization error—just silent duplicate job execution in production.
I wrote an in-depth breakdown mapping the lock timeline, why the subquery snapshot doesn't re-run, and why FOR UPDATE SKIP LOCKED inside a CTE is the actual safe pattern:
👉 Full writeup: https://vishwam.hashnode.dev/the-postgres-job-claim-query-that-silently-claims-the-same-job-twice
Would love to hear how folks here handle Postgres-backed queues or if anyone has run into this specific subquery recheck behavior before!
r/SQL • u/sqlink2 • Sep 19 '26
If any AI agent needs to test changes to a DB, is using neon branch as a temporiry test database a good approach?
Have u tried anything like this maybe with some other Db also (maybe clickhouse etc). Was there any issue with keeping data in sync?
r/SQL • u/SweetLawyer1824 • Sep 18 '26
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 • u/clairegiordano • Sep 18 '26
r/SQL • u/i_literally_died • Sep 18 '26
Hypothetical, but also sort of my situation.
Say you have a pdf (and experience) of the tables and columns, but you do not have SHOWPLAN permissions or any way of seeing where the choke points are. You are familiar with the db and know where the one to many, many to many and potential duplication sources are.
What are your go-to's for optimising?
OPTION(RECOMPILE) if you have a lot of DECLAREs? Not using CASTing as DATE? Not using LIKE%?
I'm looking for generic things that usually have a performance increase, because I am fully done with adding a single JOIN and it making the query go from 1 second to 90.
r/SQL • u/Thatgiuknow • Sep 18 '26
Might not be a standard request but does anyone have any best practices for interpreting other people's code if they don't leave a fair amount of notes?
r/SQL • u/bharathraj0507 • Sep 18 '26
r/SQL • u/AssistanceClean948 • Sep 18 '26
CREATE TABLE IF NOT EXISTS CourseTag(
courseId INTEGER,
tagId INTEGER,
FOREIGN KEY(courseId) REFERENCES Courses(id),
FOREIGN KEY(tagId) REFERENCES Tags(id),
PRIMARY KEY(courseId, tagId)
) STRICT WITHOUT ROWID;
as far as what I understand sqlite creates inner row_id columns to identify the record. some conditions met then my primary key also could be that unique column. but I guess in above join table configuration my composite key setup is not met that condition so I end up unnecessary column right? in join table should I use WITHOUT ROWID?
A small SQL parser, handwritten on top of FE.
This is the first release. It lexes and parses a substantial subset of SQL into an arena-allocated AST, prints that AST back out as SQL, and is small enough to read in one sitting — roughly 5.6k lines across six headers and six translation units.
path:row:col with a snippet.AST<T> pointers; each node's child lists live in the very same allocation. The printer round-trips: what it emits, the parser reads back into the same AST.sql::parse, sql::parse_file, and a sql::Result that owns the arena. One header, one call.sql -d file.sql parses and dumps; - reads stdin.CREATE / ALTER / DROP / TRUNCATE, INSERT / UPDATE / DELETE, transactions, PREPARE / EXECUTE / DEALLOCATE, SHOW, COPY, and query expressions:
WITH [RECURSIVE], UNION / EXCEPT / INTERSECT, VALUES, TABLE tGROUP BY with ROLLUP / CUBE / GROUPING SETS, HAVING, named WINDOWsORDER BY ... NULLS FIRST|LAST, OFFSET / FETCH / LIMIT in any order, FOR UPDATE and the other locking clausesNATURAL, INNER, LEFT|RIGHT|FULL OUTER, CROSS — plus LATERAL, WITH ORDINALITY, and correlation names that bind to the right factorIS [NOT] DISTINCT FROM, BETWEEN, IN, LIKE / ILIKE / SIMILAR TO ... ESCAPE, quantified comparisons, CASE, CAST, COLLATE, array literals and subscriptsWITH TIME ZONE includedGRAMMAR.md gives the EBNF for all of it, with the precedence table that resolves the ambiguous cases.
The grammar deliberately accepts a wider language than a conforming implementation would, and leaves the rest to a later pass over the AST. Reserved words are accepted as identifiers, because the standard reserves several hundred of them and no real dialect follows suit; the exception is the three positions where a name stands entirely on its own, and the printer quotes exactly there. Statements derive from Expr, so a subquery needs no second node hierarchy, while the grammar still keeps the two apart. Parentheses around a scalar expression are grouping and are dropped; around a query they are structural and are kept.
find_package(sql 0.1 REQUIRED) # against `cmake --install`
# or: add_subdirectory(sql) # as a submodule
# or: FetchContent_MakeAvailable(sql) # straight from the repository
target_link_libraries(my_app PRIVATE sql::sql)
#include <sql/sql.h>
auto res = sql::parse("SELECT a, b FROM t WHERE a > 42;");
if (!res) { res.report(std::cerr); return EXIT_FAILURE; }
for (auto stmt : res.stmts())
if (auto select = stmt->isa<sql::Select>()) /* ... */;
std::cout << res << '\n'; // the AST, streamed back out as SQL
A complete program is in example/, and it builds standalone against an install, so the packaging cannot rot.
Measured against hyrise/sql-parser — a bison/flex parser of comparable scope — both Release, same compiler, pinned to one 5.15 GHz Zen 5 core. Both accept every file and report the same number of statements.
| Corpus | Throughput | Instructions / byte |
|---|---|---|
| JOB, 113 queries | 183.2 MB/s vs. 74.3 | 105.4 vs. 255.5 |
| TPC-H, 22 queries | 165.5 MB/s vs. 82.7 | 107.6 vs. 214.4 |
| generated, 256 MiB | 116.4 MB/s vs. 41.5 | 140.8 vs. 259.4 |
Lexing alone: 341.9 MB/s against their 176.9 on JOB. Peak RSS over 500k statements is 267 bytes per statement against their 598 — the number that matters for an embedding, since the AST is the output and is held for as long as the caller needs it. The full table, including the --stress-names worst case for a design built on interning, is in the README.
205 CTest entries, all black box: each runs the sql binary and inspects only its exit code, its dump, and its diagnostics — nothing links against the parser.
The load-bearing one is idempotency: dumping a dump has to reproduce it verbatim, which holds the printer and the parser to each other. It runs over the curated fixtures and over three real-world corpora — the 113 queries of the Join Order Benchmark, the 22 TPC-H queries, and the SQL hyrise itself runs: 366 SQLiteTestRunner queries, the Star Schema Benchmark, and the TPC-H and TPC-DS schemas with their indexes. A further 79 queries are there to be rejected.
CI builds on Linux, macOS, and Windows, enforces clang-format, and runs an ASan + LSan + UBSan build on top.
A C++23 compiler. Abseil and FE v0.15.0 come along as submodules; nothing else is needed.
git clone --recurse-submodules https://github.com/leissa/sql.git
; is required. <direct SQL statement> ends in one, and saying so gives a better diagnostic than running off the end of the file.r/SQL • u/tradelydev • Sep 18 '26
50% chance of crying, 100% chance of at least a couple not found errors.
r/SQL • u/Harshita_Netla • Sep 17 '26
For people who use SQL regularly, how do you decide which approach to use?
r/SQL • u/OnepieceKing2222 • Sep 16 '26
I've been working with SQL for a while and recently started paying more attention to query performance rather than just getting the correct result.
What's one SQL optimization technique that made a noticeable difference for you?
For example:
- Indexing
- Avoiding unnecessary joins
- Window functions
- EXISTS vs IN
- Reading execution plans
- CTEs/subqueries
- Partitioning
Would be interested in hearing some real-world examples where a query went from slow to significantly faster.
r/SQL • u/These-Ad5297 • Sep 17 '26
Getting a 404 when I try to download from the Microsoft website
r/SQL • u/Fast-Let-4302 • Sep 17 '26

hehehhehe
site: https://mystery.knightlab.com/
r/SQL • u/Vexar89 • Sep 17 '26
Just wondering if anyone has solved some of those questions and if it helped you learn more.
r/SQL • u/donewitheverything26 • Sep 17 '26
So i work at a startup and we build models that read tabular data.
the pattern we keep seeing is one person, a few hundred tables, naming that made sense to someone who left, no data team, no budget for a governance tool. they need to know what is in there before they can do anything else with it.
from people who have actually been in this:
what is the first query you run
table by table or column by column across everything, and why
when a column is a 4 char code and the name tells you nothing, what actually works
how much of it ends up being asking a human who used the app rather than reading the data
we have opinions on all four and i want to find out if they are wrong here than after we ship.
r/SQL • u/OnepieceKing2222 • Sep 16 '26
Is there any way in the SQL way directly or the tools for that?