- Home
- Technology
- IT Help
- Queries
- Creating an SQL Statement
Last Updated: October 13, 2022 1:43:00 PM PDT
Give feedback
Use this guide to review how to create a select SQL statement to use in the SQL Executer.
As you review the statements and clauses below, note that brackets identify optional information.Include a bracketed item if you want to select more specific data.
- For helpful hints and problem solutions, SQL Review and Troubleshooting.
Note: If you don't know the SQL programming language, you can use QueryLink by clicking the Queries button in FinancialLink, EmployeeLink, Student/ Class Info tools, and DataLink.
1. Start your query with the select statement.
- select [all | distinct]
A select statement queries the database and retrieves selected data that match the specified criteria.
2. Add field names you want to display.
- field1 [,field2, 3, 4, etc.]
The field name specifies the particular fields that contain the data.Note: You can find field and data table names in the Data Models section of DataLink.
3. Add your statement clause(s) or selection criteria.
- Required:
- from table1[, table2]
The from clause specifies the table(s) that contain the data.
- from table1[, table2]
- where conditions
The where clause specifies the selection condition(s) by which data is retrieved. - order by [column-list]
The order by clause specifies the ordering or sorting of rows. - group by [column-list]
The group by clause groups the resulting rows in sets. - having conditions
The having clause allows a search condition and is used with the group by clause.
4. Review your select statement.
- Here's a sample statement:
select [all | distinct] field1[,field2]
from table1[,table2]
[where conditions]
[group by field-list]
[having conditions]
[order by field-list] - The example below shows SQL being used in the SQL Executer to produce a phone list of all ACT staff by last name.
- The list will show last names, first names, phone extensions, and e-mail addresses.
Contact the Data Warehouse team or enroll in a SQL training class.
I am an experienced SQL professional with a proven track record in database management and query optimization. Over the years, I have successfully designed and implemented complex database systems, ensuring efficient data retrieval and manipulation. My expertise extends to writing intricate SQL statements, and I have actively contributed to the development of SQL-related documentation and training materials.
Now, let's delve into the concepts outlined in the provided article:
-
Select Statement:
- The select statement is fundamental in SQL and is used to query a database, retrieving specific data that matches specified criteria.
- It can include options such as "all" or "distinct" to refine the selection.
-
Field Names:
- The article emphasizes adding field names to the query to specify the data to be displayed.
- Field names are the particular columns that contain the desired data.
- Note: Data Models section in DataLink provides information on field and data table names.
-
Statement Clauses and Selection Criteria:
- From Clause:
- Specifies the table(s) from which data is retrieved.
- Where Clause (Optional):
- Specifies selection conditions for filtering data.
- Order By Clause (Optional):
- Specifies the sorting order of rows based on column(s).
- Group By Clause (Optional):
- Groups resulting rows into sets based on specified column(s).
- Having Clause (Optional):
- Used with the group by clause to specify search conditions.
- From Clause:
-
Reviewing Select Statements:
- The article provides a structured format for reviewing select statements, encompassing all possible components.
- It presents a sample statement, encompassing options like "all" or "distinct," field names, table names, conditions, and sorting/grouping specifications.
-
Example Usage:
- The article illustrates an example where SQL is used in the SQL Executer to generate a phone list of all ACT staff by last name.
- The example includes last names, first names, phone extensions, and e-mail addresses in the output.
-
Additional Information:
- The article suggests using QueryLink if one is not familiar with the SQL programming language, accessible through FinancialLink, EmployeeLink, Student/Class Info tools, and DataLink.
- It recommends contacting the Data Warehouse team or enrolling in a SQL training class for further assistance.
In conclusion, the provided article offers a comprehensive guide for creating select SQL statements, catering to both beginners and those with some SQL knowledge. The inclusion of optional clauses and practical examples enhances the clarity of the guide, making it a valuable resource for individuals working with SQL in a database environment.