How to Create an SQL Select Query in Access
Microsoft Access allows you to create both personal and professional databases. In addition to regular queries, Access also provides the tools needed to create SQL Select queries. An SQL Select query can be customized further than a typical Select query. Basic SQL knowledge is necessary. Access does provide you with both the basic terms and syntax.
Instructions
-
-
1
Open an existing Access database. Click "Queries" in the database window.
-
2
Create a new query in Design View or open an existing query in Design View. Press the "Design" button with the desired query highlighted to open in Design View.
-
-
3
Locate the "View" button on the toolbar. This is typically the first button on the query toolbar. Custom toolbars may have the button in a different location. Press the arrow next to the "View" button and select "SQL View."
If your query is something other than a Select query, change the query type first. Change the view back to "Design View." Use the "Query Type" button to change the type to "Select."
-
4
Start the query with the word "SELECT." Type the fields you wish to select next, separated by commas. The fields should be in the format TableName.FieldName. Press "Enter" and type the word "FROM." Type the table name you wish to select the field names from. If you're only selecting fields from a single table, field names don't need to be preceded by the table name.
For instance, a basic Select query would look similar to the following:
SELECT SampleTable.FirstField, SampleTable.SecondField
FROM SampleTable; -
5
Add criteria and ordering by using the term "WHERE" plus your criteria. With multiple tables, always precede field names with the table name. Use the term "ORDER BY" along with the table name and field. Ascending is the default sort order. Use "DESC" at the end of the line for descending order.
For instance, the query would now look like the following:
SELECT SampleTable.FirstField, SampleTable.SecondField
FROM SampleTable
WHERE (SampleTable.FirstField = "ThisText")
ORDER BY SampleTable.SecondField; -
6
Follow the last line of the Select query with a semicolon.
-
1
Tips & Warnings
Use the table name along with field names even in simple queries to prevent errors in more complex queries.
Always place the semicolon at the end of the last line. The query will not run if this is missing.