Querying Databases: Definitions and Essential Tools, Explained

UPI Study › Courses › Database Programming › Free lessons › Lesson 1.4 Free with a free account

Querying Databases: Definitions and Essential Tools

Database Programming · Chapter 1: Getting Started with Databases and SQL SetupSection 1.4 · lesson 4 of 768 min · free with a free account

← Planning a Database Schema: Key Ideas and StepsNext lesson: DDL, DML, and DCL in MySQL: What They Do and When to Use Them →

A free account plays all of Chapter 1 and 3 more lessons of Database Programming. Create a free account →

Earn 3 college credits for Database ProgrammingRecommended for credit by NCCRS · Computer Science 381 · self-paced · one payment, lifetime access

In this lesson

Write basic SELECT queries and read the result sets they return.

  • Define a query, a SQL statement, and a result set
  • Use SELECT, FROM, and WHERE to choose columns and filter rows
  • Distinguish quoted text literals from identifiers and interpret empty results
  • Run saved .sql scripts with MySQL, SQL Server, and SQLite client tools

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (984 words). Read along, or search it.

Opening Question

Asking for Customers in Pune

Maya needs a list of customers in Pune. The stored records already exist; how does she ask for just the answer she needs? A query is a request for data. A SQL statement expresses that request in a form the database engine can interpret. A result set is a table-shaped answer, with named columns and zero or more rows. It is separate from the stored table.

Sample Data

The Lantern Books Customers Table

Our sample is the customers table at Lantern Books. Each record has an identifier, first and last names, city, and points. The supplied setup file creates those fictional records. We are using SQLite for the runnable demonstrations; the basic queries transfer to MySQL and SQL Server. Run the setup once, in a fresh practice folder. It creates the local shop database file; successful setup prints no rows. These are prepared records. Table creation comes later.

Select Everything

SELECT Star with ORDER BY

Select star from customers requests every column from that table. The star is shorthand for all columns. We add order by customer ID for a predictable display. Without an ordering clause, the engine does not promise a particular row order. Run the file through the SQLite shell, using header and column display options. Those options format the terminal answer; they do not change the query. The answer has six rows and five columns, matching the shared fictional sample.

Choosing Columns

Selecting First Name and City

Now select first name and city, from customers. Select names the result columns; commas separate their names. From names the source table. The source still contains all its original columns, even though this request asks for fewer. Run the statement. The answer becomes narrower; stored information remains intact. The result has six rows, with only first name and city. Reversing the selected column names would reverse their display order.

Filtering Rows

WHERE Keeps Rows That Test True

Add where city equals Pune. Where supplies a condition, which is a test applied to the candidate rows. Pune is a text literal, so it belongs inside single quotes. Keep rows only when the condition evaluates to true. Run the file. The logical reading model is from the source, through the filter, to the selected columns. Asha, Chen, and Farid remain. The result contains three rows and two columns; the stored customers table remains intact.

Logical Model

Reading Order Versus Engine Execution

The logical model helps you predict an answer, but it is not a promise about the engine's physical execution steps. The optimizer can choose indexes and other strategies, while preserving the meaning of the request. Uppercase keywords aid readability. Lowercase select has the same meaning; names and text comparisons depend on dialect and collation.

Numeric Filter

Filtering by Customer ID Four

A numeric condition needs no text quotes. Here, customer ID equals four, so the request targets one identified record. The selected columns are still first name and city. A filter may use a column that is absent from the result. Run the request, and inspect the returned values. The identifier selects Dara, whose city is Lagos. These ordinary select statements read the records, without changing them.

Empty Results

No Matching Rows Is Not an Error

What if no row meets the condition? This request asks for customers in Oslo, which is absent from our sample. Run it. SQLite's column display prints no result rows here, and no header; that is an empty answer, rather than an error. A graphical grid may still show column names, despite containing zero records.

Common Mistake

Unquoted Pune Becomes an Identifier

Here is a common slip: Pune appears without single quotes. The engine treats that unquoted word as an identifier. Our customers table has no column with that name. Run this faulty statement to see the actual SQLite message. The diagnostic says no such column, and names Pune. The wording is SQLite's; MySQL and SQL Server report their own diagnostics. Single quotes would express a text value, rather than an identifier.

Query Tools

Language Versus Interface

SQL is the language; the query tool is the interface. MySQL's mysql client and SQL Server's sqlcmd work in text terminals. Workbench provides a MySQL editor and result grid. On Windows, SSMS provides an object browser, editor, Execute action, results, and messages. Azure Data Studio retired in February, twenty twenty-six. Use a supported tool, such as Visual Studio Code with its MSSQL extension, instead of an old installation guide.

Saved Scripts

SQL Files, Comments, and Semicolons

A script is a plain-text file of saved statements, normally ending in .sql. Save it to repeat work and share the exact request. A double-dash comment explains the purpose without changing the result. In MySQL, follow the dashes with a space. End statements with semicolons. Missing separators, misspelled names, or a missing from clause can produce errors; inspect the actual message rather than guessing. In graphical tools, selected text changes what executes. Check the selection before expecting the whole saved file to run.

Running Scripts

Client Commands for Saved Files

For MySQL, choose shop with use shop, then run a query. The client can read a saved file with its source command. For SQL Server, sqlcmd accepts a database and an input file. Go on a line by itself submits a batch in Microsoft tools. GO and source are tool instructions, rather than portable SQL statements. SQLite opens shop.db through the shell command shown earlier. Workbench and SSMS also open script files. Use the command for the server and tool you actually installed.

Quick Check

Predict the Shape for Customer Six

Quick check: the request selects city and points, where customer ID equals six. Predict the result's shape, before running it. Read the choices, then pause, and predict.

Answer Explained

One Row and Two Columns

One row and two columns. The run returns Pune and ninety-five points, because customer ID six identifies Farid. Select controls the columns, while where limits the rows. The other choices confuse stored-table size with the shape requested by this statement. The result provides exactly the selected properties for the matching record, without changing that record.

Key Takeaways

Queries, Filters, and Result Sets

A query asks for data, and a result set is its table-shaped answer. Select chooses columns, from names a source, and where keeps qualifying rows. An empty answer can be valid. Use quoted text, exact object names, and semicolons. Read diagnostics separately from successful query results. Save repeatable scripts, and match the client instructions to the engine you are using.

About Database Programming at UPI Study

Database Programming (Computer Science 381) is a self-paced online course of 76 video lessons in 12 chapters, from database applications, SQL setup, schema planning and normalization to keys and constraints, data types, filtering and sorting, joins, subqueries, views, indexes, ROLLUP and PIVOT, regular expressions and database security. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Database Fundamentals vs Database Programming

Why take it here

Why students take Database Programming with UPI Study

Write the SQL behind every appDatabase Programming teaches SQL in MySQL and SQL Server side by side: designing and normalizing tables, keys and constraints, data types, inserting, updating and deleting rows, filtering, grouping, joins, subqueries, views, indexes, transactions, and protecting data from SQL injection. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Database Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Querying Databases: Definitions and Essential Tools

What is the difference between a query and a result set?
A query is a request for data, and a result set is the table-shaped answer the database returns. A SQL statement such as SELECT first_name, city FROM customers WHERE city = 'Pune'; expresses the query. The result set has named columns and zero or more rows, and it is separate from the stored table. Reading data with an ordinary SELECT does not change the stored records.
Why does a text value in a WHERE clause need single quotes?
Single quotes mark a text literal; without them, the database reads the word as an identifier, such as a column name. Writing WHERE city = Pune makes the engine look for a column named Pune, and SQLite reports no such column: Pune. Writing WHERE city = 'Pune' compares each row's city with the text value. Numeric values, as in WHERE customer_id = 4, need no quotes.
What tools can run SQL queries on MySQL and SQL Server?
SQL is the language, and a query tool is the interface used to send it. MySQL offers the mysql command-line client and the graphical MySQL Workbench. SQL Server offers the sqlcmd command-line tool and, on Windows, SQL Server Management Studio, or SSMS. Visual Studio Code with the MSSQL extension is another supported option, since Azure Data Studio was retired in February 2026.
Is a SQL query that returns no rows an error?
No, a query that matches no rows returns a valid empty result set. For example, asking for customers in a city that does not appear in the table returns zero rows. A command-line shell may print nothing at all, while a graphical grid may still show the column names above an empty grid. A real error, such as a misspelled column name, produces a diagnostic message instead.

About the Database Programming course

How many college credits is Database Programming?
Database Programming (Computer Science 381) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Database Programming cost and what is included?
$250, paid once, with lifetime access: all 76 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Database Programming take?
It is self-paced with no deadlines. The 76 lessons total about 11 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Database Programming.

76 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Database Programming
3 credits · NCCRS
Enroll →