SELECT, filter and sort in SQL for clear beginner queries
Learn how to use SELECT, WHERE and ORDER BY in SQL to pick columns, filter rows and sort results so your data answers real questions.
What SELECT does and how to read query results
SELECT tells the database which columns you want to see. You read the result like a spreadsheet: each row is a record, each column is a field. As a beginner, focus on simple queries first, for example selecting a few key columns from one table. This helps you check what data you actually have before you try complex logic. Use SELECT * only while exploring a small table. For day to day work as a data analyst, it is better to name the columns you need, because this keeps queries readable and avoids surprises when tables change.
- •Quick for first exploration
- •Returns all columns
- •Harder to read in big tables
- ✓Shows only what you need
- ✓More stable when schema changes
- ✓Clear for teammates and future you
How to select specific columns from a table
In practice, you rarely want every column. Use SELECT with a comma separated list of columns and a FROM clause that names the table. Start with the business question, then think which columns help answer it, for example customer_id, order_date and total_amount. You can also rename columns with AS to make reports clearer. Be careful with typos in column names, because many SQL tools only show a blank column or error messages. Get into the habit of running and checking small queries, then extend them once you trust the output.
- 📂1Name tableDecide which table to query
- ✅2Pick columnsList only columns you need
- 👀3Run and checkScan a few rows for sense
Filtering rows with WHERE for relevant data
WHERE limits which rows are returned so you see only relevant data. You can filter on text, numbers and dates with operators like =, >, <, BETWEEN, LIKE and IN. Combine conditions with AND for stricter filters and OR for broader ones. Order matters for your thinking, not for SQL, so use parentheses when logic gets complex. Typical beginner mistakes are forgotten quotes around text values and using OR where AND was intended. Always sanity check counts before and after adding a WHERE clause to see if the change matches your expectation.
Sorting results with ORDER BY to see patterns
ORDER BY lets you decide how rows are sorted in the result set. Use ASC for ascending order or DESC for descending. A data analyst often sorts by date to see the latest events first or by a metric like revenue to find top or bottom performers. You can sort by several columns in sequence, for example by region and then by total_amount. A frequent mistake is to rely on the default order of results, which is not guaranteed. Always state your desired order in the query so your findings are repeatable and easy to verify.
Combining SELECT, WHERE and ORDER BY in real work
Most day to day queries mix these three pieces. You SELECT the columns that matter, use WHERE to filter to the time frame, product, region or user group, then ORDER BY to get a useful view. Think of it as moving from all rows to a focused and readable answer to a question. Keep queries simple at first, for example start without WHERE or ORDER BY and add them step by step. If a result looks wrong, remove one part at a time until it makes sense again, then rebuild the logic carefully.
- 📋1Start with SELECTChoose table and columns
- 🎯2Add WHEREFilter to the needed rows
- 📊3Add ORDER BYSort to reveal patterns
- 🔍4Review outputCheck counts and values
Real-world examples
- • Your manager asks for a list of all customers who placed an order in the last 7 days, sorted by the highest order amount. You write a query that selects customer_id and order_total, filters with a WHERE condition on order_date and orders the results by order_total DESC.
- • You want to check which support tickets remain open and have the oldest creation dates. You query the tickets table, select ticket_id, status and created_at, filter WHERE status = 'open' and ORDER BY created_at ASC so the longest waiting tickets appear first.
Useful links
- PostgreSQL official documentation — See the SQL language section for SELECT and WHERE examples.
- SQLite documentation — Lightweight reference for basic SELECT queries and syntax.
Keep learning
Learn simple spreadsheet steps to spot errors, clean messy columns and fix basic data quality issues before serious analysis.
How to use AI tools to practice and improve your SQL safelyLearn how to draft, debug and understand SQL with AI tools while still checking results yourself so you truly build real skills.
Analytical thinking process: from problem to clear insightsLearn a simple analytical thinking process from framing your problem to extracting data, analyzing results and communicating clear, useful insights.
Related courses
More programs on evelin that fit this path. Each one adapts to you after a two minute quiz.
Land Your First Remote Job
You bring your goals and answers, this course shapes itself to your field and pace, adapts with every application you send, and stays by your side beyond your first remote offer
Explore the course →How to Become a Freelance Developer
You turn this into your own path: every answer shapes what comes next, every step adapts to your freelancing style, and the guidance stays with you beyond your first booked client.
Explore the course →How to Master Digital Marketing
This course grows with your business: every answer shapes your path, every step adapts to your channels, and the work continues beyond the first wins into a lasting marketing habit.
Explore the course →How to Become an AI Workflow Designer
This course grows with your experiments. Every answer reshapes your path, every workflow builds on your tools, and your learning continues as your automations run in the real world.
Explore the course →Guides from related courses
- Remote work fundamentals: setups, tools, and daily expectations · Land Your First Remote Job
- Client acquisition channels for new freelance developers explained · How to Become a Freelance Developer
- Paid ads testing basics: how to learn fast on a small budget · How to Master Digital Marketing
Turn reading into real progress
A short quiz builds your personal learning path for How to Become a Data Analyst. Lessons adapt to you from day one.
Start the quizCreated with AI assistance and reviewed before publishing.