SShortSingh.
Back to feed

SQL's COUNT Function: How COUNT(*), COUNT(column), and COUNT(DISTINCT) Differ

0
·1 views

The SQL COUNT function has three distinct forms that behave differently and commonly confuse developers in interviews and on the job. COUNT(*) tallies every row in a table regardless of NULL values, while COUNT(column) only counts rows where the specified column is not NULL. COUNT(DISTINCT column) goes further by counting only unique non-NULL values in that column. The gap between COUNT(*) and COUNT(column) is a practical way to measure missing data in a dataset. Comparing COUNT(*) with COUNT(DISTINCT column) also serves as a quick method to detect duplicate records in a table.

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 ·

Developer corrects a 'never published' status field — only to find the article was already live

A software developer writing about stale status fields in documentation made the very error they were cautioning against. While reviewing a drafts folder, they misread a YAML front-matter flag — 'published: true' — as a historical record rather than a build instruction, and confidently marked the article as never published. The article had in fact been live for over a day on a separate platform, a fact recorded in the team's own backlog file. The mistake was only caught when a duplicate-post attempt returned a 'title already exists' error. The developer noted that a confident correction, made with less verification than the original claim, can be more misleading than the ambiguous field it replaces.

0
ProgrammingDEV Community ·

Codename One Adds Portable Routing API to Simplify In-App Navigation

Codename One, an open-source framework for building cross-platform apps in Java or Kotlin, has introduced a new routing module via pull request #5480. The update adds a com.codename1.maps.routing package that models road geometry, waypoints, distances, durations, and encoded polylines. Developers can use a simple two-line call for basic route display or a callback-based API for advanced needs like ETAs, alternatives, and custom styling. The default routing backend is the open-source OSRM demo server, which requires no API key but is not intended for production use. The design abstracts the service layer so application code works with a standard Route model regardless of the underlying routing provider.

0
ProgrammingDEV Community ·

GitHub Combines Admin UI and Billing API to Help Orgs Control AI Spending

GitHub administrators can use the Metered Usage dashboard alongside the Billing Usage API to investigate and manage rising AI costs more effectively. The Admin UI allows admins to identify spending increases by period, organization, or cost center within a few clicks. The Billing Usage API complements this by enabling reusable, automated reports tailored to a company's specific reporting needs, such as finance calendars or team-level breakdowns. Together, the two tools help admins pinpoint whether a spending spike is broadly distributed or concentrated among a few users before applying any restrictions. The goal is to protect productive workflows while addressing unexpected cost drivers through targeted budget controls.

0
ProgrammingDEV Community ·

Developer Launches KiterPDF, a Free Browser-Based Toolkit for Common PDF Tasks

A developer has built and released KiterPDF, a free online toolkit designed to simplify everyday PDF-related tasks in one place. The platform currently offers five tools: compress, merge, split, PDF to JPG conversion, and page rotation. It supports files up to 200MB and includes compression targets such as 100KB, 500KB, and 1MB to help users meet specific file-size requirements. The project was motivated by frustration with having to visit multiple different websites to complete basic PDF operations. KiterPDF aims to provide a straightforward, five-step workflow — choose a task, select a file, adjust options, process, and download — without unnecessary complexity.