A Select query retrieves information from one or more tables and displays the results in Datasheet View. It can display selected fields, filter records, sort data, and combine related information without directly changing the source data.
A Select query is a query used to retrieve records that meet specific requirements. It is one of the most frequently used query types in Microsoft Access.
| StudentID | StudentName | Course | Fees |
|---|---|---|---|
| 101 | Amit | ADCA | 10000 |
| 102 | Priya | Tally Prime | 4000 |
| 103 | Rahul | ADCA | 10000 |
| 104 | Neha | Web Development | 12000 |
A Select query can display all students, show only student names, or find students enrolled in ADCA.
qryStudents, qryADCAStudents,
or qryHighFees to identify queries easily.
Use the asterisk (*) to retrieve all fields from a table.
SELECT *
FROM Students;
SELECT specifies the data to retrieve.* means all fields.FROM Students specifies the source table.This query displays all fields and records in the Students table.
You do not always need to display every field. You can select only the fields required for a report.
SELECT StudentName, Course
FROM Students;
This query displays only StudentName and Course. StudentID and Fees are not included in the results.
SELECT StudentID, StudentName, Fees
FROM Students;
This query displays the student ID, student name, and fees fields.
The WHERE clause filters records according to a specified condition.
SELECT *
FROM Students
WHERE Course = "ADCA";
This query displays only students whose course is ADCA.
SELECT StudentName, Fees
FROM Students
WHERE Fees > 5000;
This query displays the names and fees of students whose fees are greater than 5000.
SELECT StudentName, Fees
FROM Students
WHERE Fees < 10000;
This query returns students whose fees are less than 10000.
AND requires both conditions to be true.
SELECT *
FROM Students
WHERE Course = "ADCA"
AND Fees > 5000;
This query finds students whose course is ADCA and whose fees are greater than 5000.
OR returns records that satisfy at least one of the specified conditions.
SELECT *
FROM Students
WHERE Course = "ADCA"
OR Course = "Tally Prime";
This query displays students enrolled in ADCA or Tally Prime.
The ORDER BY clause arranges query results in ascending or descending order.
SELECT StudentName, Fees
FROM Students
ORDER BY StudentName ASC;
This query arranges student names alphabetically. ASC means ascending order and is the default sort direction.
SELECT StudentName, Fees
FROM Students
ORDER BY Fees DESC;
This query displays students with the highest fees first. DESC means descending order.
SELECT StudentName, Course, Fees
FROM Students
ORDER BY Course ASC, StudentName ASC;
This query sorts students by course and then alphabetically by student name within each course.
The DISTINCT keyword returns only unique combinations of the selected fields.
SELECT DISTINCT Course
FROM Students;
If many students are enrolled in ADCA, this query displays ADCA only once in the results.
If you select more than one field with DISTINCT, Access returns unique combinations of those fields.
A Select query can retrieve related information from more than one table when the tables are connected through appropriate fields.
Students Table
Courses Table
SELECT Students.StudentName,
Courses.CourseName
FROM Courses
INNER JOIN Students
ON Courses.CourseID = Students.CourseID;
This query combines related records from both tables and displays each student's name with the associated course name.
An INNER JOIN returns records where the join condition matches in both tables.
Create a table named Students with these fields:
Goal: Practice retrieving selected fields, filtering data, sorting results, and removing duplicate query output.
1. Which SQL statement retrieves all fields from Students?
2. Which clause filters records?
3. Which keyword sorts fees from highest to lowest?