SShortSingh.
Back to feed

SQL Subqueries and CTEs Explained Using a Beekeeping Database

0
·1 views

A tutorial on DEV Community uses a fictional beekeeping co-op dataset to explain how subqueries and Common Table Expressions (CTEs) work in SQL. Subqueries are nested queries wrapped in parentheses that the database resolves first, passing their result to the outer query. They can return a single scalar value, a list, or a full result set, and can be correlated — re-running for each row in the outer query. The article highlights a key pitfall: using NOT IN with a subquery that may return NULL values can silently eliminate all results, making NOT EXISTS a safer alternative. CTEs are presented as an alternate syntax for the same logic, offering improved readability for complex, multi-step queries.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Why Engineers Should Ditch the 25-Minute Pomodoro Rule for Custom Work Cycles

A DEV Community article argues that the classic 25-minute Pomodoro interval, designed in the 1980s for paper-based clerical tasks, is poorly suited to modern software engineering work. Engineers typically operate across much longer focus spans — from quick Slack triage to 90-minute deep debugging sessions — making a one-size-fits-all timer counterproductive. The article recommends logging several typical workdays to identify dominant focus patterns, then selecting a block length that matches actual task complexity. A simple model presented shows that a 50/10-minute cycle yields roughly 82% effective focus time under realistic interruption loads, compared to about 63% on the traditional 25/5 cadence. Certain situations, such as active incident response, are flagged as exceptions where timers should be paused entirely rather than followed rigidly.

0
ProgrammingDEV Community ·

How React Transforms State Changes Into Browser Pixels: A Mental Model

React operates on a core principle where the UI is treated as a function of state, meaning any state change triggers a recalculation of what the interface should look like. When developers write JSX, it is not converted directly into HTML but into plain JavaScript objects called React Elements, which serve as blueprints for the UI. React then compares a newly generated tree of these elements against the previous one before deciding which, if any, real DOM updates are needed. This reconciliation process means that a component can re-render multiple times without necessarily causing any browser DOM mutation. Understanding this distinction between rendering and DOM updates is key to writing performant React applications and diagnosing hard-to-trace bugs.

0
ProgrammingDEV Community ·

DEV Community Writer Celebrates Reaching 1,001 Profile Views

A writer on the DEV Community platform recently hit a personal milestone of 1,001 total profile views. The author expressed gratitude to the community for their engagement, including reading articles, leaving comments, and reacting to posts. When they began publishing, they were uncertain whether their content would find an audience. Reaching this milestone has proven motivating and encouraged them to continue writing and learning. They also invited fellow creators to share their own memorable milestones in the comments.

0
ProgrammingDEV Community ·

Brazilian Lottery Portal Uses SHA256 Hashing to Make Data Changes Publicly Auditable

A Brazilian lottery results portal, deunobicho.online, has implemented SHA256 content hashing to address public distrust over potential data tampering. The system generates a cryptographic hash of each lottery result's canonical JSON at the time of publication, making any subsequent alteration detectable. Each published result is accompanied by a public evidence page displaying the raw data, its hash, a timestamp, and a link to the official source. If a correction is ever necessary, a new evidence page with a new hash is created and both versions are linked in an audit log. The approach allows any reader to independently verify that data has not been silently changed since it was first published.