Select columns across different databases
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Selecting specific columns instead of SELECT * is a fundamental practice for database performance, bandwidth reduction, and API clarity. While the basic SELECT syntax is similar across SQL databases, each database system has unique features for column selection — computed columns, JSON extraction, column aliasing, and cross-database queries. NoSQL databases like MongoDB and DynamoDB have their own projection mechanisms entirely.
SQL Databases: Basic Column Selection
The core syntax is the same across MySQL, PostgreSQL, SQL Server, and SQLite:
MySQL
PostgreSQL
SQL Server
SQLite
Cross-Database Queries in SQL
Querying across different databases on the same server:
MongoDB (NoSQL)
MongoDB uses projection to select fields:
DynamoDB
Redis
ORM Examples
Common Pitfalls
- SELECT * in production:
SELECT *retrieves all columns, including large text/blob fields you may not need. It wastes bandwidth, prevents covering index optimization, and breaks when columns are added or renamed. Always specify columns. - Column name conflicts in JOINs: When joining tables with same-named columns (e.g., both have
id), use aliases:SELECT u.id AS user_id, o.id AS order_id. - Cross-database query permissions: Querying across databases requires permissions on both databases. In SQL Server, linked servers require separate authentication configuration.
- Case sensitivity varies: MySQL column names are case-insensitive on most systems, PostgreSQL is case-insensitive unless quoted (
"Name"vsname), SQL Server is case-insensitive by default but configurable. - MongoDB projection mixing: You cannot mix inclusion and exclusion in the same projection (except for
_id).{ name: 1, email: 0 }is an error — use either{ name: 1 }or{ email: 0 }.
Summary
- Use explicit column names instead of
SELECT *for performance and clarity - MySQL uses backticks for identifiers, PostgreSQL uses double quotes, SQL Server uses square brackets
- Cross-database queries: MySQL uses
db.table, SQL Server usesdb.schema.tableor linked servers, PostgreSQL uses Foreign Data Wrappers - MongoDB uses projection objects (
{ field: 1 }) instead of SELECT - ORM equivalents:
.values()(Django),query(Model.col)(SQLAlchemy),attributes(Sequelize)
Related reading
- Select data from show tables MySQL query
- SELECT FROM X WHERE id IN ... with Dapper ORM
- Select last N rows from MySQL
- Select last row in MySQL
- SELECT list is not in GROUP BY clause and contains nonaggregated column .... incompatible with sql_modeonly_full_group_by
- Select MongoDB documents where a field either does not exist, is null, or is false?
- Select multiple columns using Entity Framework
- Select Pandas rows based on list index
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.