Ask the database a specific question

An online shop might ask its database, “How much did customers spend last month?” The app sends a query; the database finds the matching orders, adds their values, and sends back the total. Developers often write queries in SQL.

Queries can also add, update, or delete information.

Getting a useful answer safely

A query that checks too many records can slow an app, even if it returns the right answer. A database index can help. Apps must also handle text users enter safely so it cannot change a query unexpectedly; that risk is called SQL injection.