Curso de SQL Server 2021 desde cero | SELECT TOP, SELECT PERCENT (video 17)
How to Select Records in SQL Server Without Filters
Introduction to SQL Queries
- The video introduces a course on SQL Server, focusing on how to perform queries without using filters. The example used is the "empleados" (employees) table.
Using the TOP Clause
- To select a specific number of records regardless of their values, the
TOPclause is utilized. For instance,SELECT TOP 5 * FROM empleados;retrieves the first five records from the table.
- The
TOPclause can also accept percentages. For example, usingSELECT TOP 50 PERCENT * FROM empleados;returns approximately half of the total records in the table.
Understanding Approximate Results
- When requesting a percentage of records, results may vary slightly due to rounding. In this case, retrieving 50% returned rows 1 through 7 out of an approximate total of 14 rows.
Filtering with TOP Clause
- The
TOPclause can be combined with filters. An example query likeSELECT TOP 3 * FROM empleados WHERE activo = 'no';fetches the first three inactive employees.