Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,190,880 members, 7,942,203 topics. Date: Saturday, 07 September 2024 at 12:25 AM

Study Explanations & Illustrations Of Sql Clauses & Keywords In Ms Acess & Mysql - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Study Explanations & Illustrations Of Sql Clauses & Keywords In Ms Acess & Mysql (1057 Views)

Programmers Help:python Code To Acess Laptop/desktop Camera / How Can I Allow Share Folder On Windows 10 For A User To Be Able To Acess It / Real Life Illustrations Of Sql In Ms Access & Mysql - Union & Join Queries (2) (3) (4)

(1) (Reply)

Study Explanations & Illustrations Of Sql Clauses & Keywords In Ms Acess & Mysql by microsofttutor(m): 9:20pm On Apr 08, 2017
It is good you get used to the various SQL clauses and Keywords in Microsoft Access and MySQL Relational Database Systems as it will hasten your rate of understanding of SQL as a whole. Here, I will explain the six most commonly used SQL clauses and Keywords in MS Access and MySQL databases. I will also explain some SQL keywords in detail and illustrate how they are used in MS Access and MySQL databases.

Detailed explanation and illustration of SQL clauses

These SQL clauses include:

1. SELECT clause
2. FROM clause
3. WHERE clause
4. ORDER BY clause
5. GROUP BY clause
6. HAVING clause

This is part 2 of chapter 6 of the Free Online Access Tutorial Series at Microsoft Tutorial website. In this part, I will explicitly explain how to learn SQL in Relational Database Management Systems (RDBMS) software like Microsoft Access 2016, 2013 and other lower versions.

In the previous part (Part 1) at http://www.microsofttut.com/2017/04/learn-sql-in-ms-access-mysql-databases.html, I explained How to build advanced queries and action queries in MS Access. Also see the full tutorial course content of this Microsoft Excel Tutorial Series at http://www.microsofttut.com/p/microsoft.html.

SELECT CLAUSE:
It consists of an operator followed by an identifier. A SELECT clause lists the fields that contain the data you wish to retrieve from a database. You can use square brackets ([]) to enclose the name of a field or identifiers in a SELECT clause. If the field name(s) does not contain spaces or special characters, the square brackets are optional. But if the field name(s) contains spaces or special characters, then you must enclose it in a pair of square brackets.

NOTES:
A name that contains spaces is easier to read and can save you time when designing forms and reports, but may make you type more when writing SQL statements. This fact should be considered when naming objects in a database.

If your SQL statement has two or more fields that have the same name but from different tables or data sources, then you must add the name of each field’s data source to the field name. The data source name is the identifier in the FROM clause of the SQL statement.

When you want to include all fields from a data source, you can either type them individually in the SELECT clause or use the asterisk wild character (*). For example, to include all the fields the customer table, you can type: customer.*.When you use the asterisk, Access determines when the query is run, which fields the data source contains and includes all those fields in the query. This helps to keep the query up to date if new fields are added later to the data source.

You can the asterisk with one or more data sources in SQL statement. If there are multiple data sources and you wish to include asterisk with only one of the data sources, then you must include the data source name together with the asterisk, so that MS Access can determine the right data source to apply the asterisk.

For example, suppose you want to select all the fields from customers table and then select only the order_dates field from the orders table, your SELECT clause should resemble this:
SELECT customers.*, oders.[order_dates];

WARNING:
Do not use the asterisk character when you intend adding new field which are not relevant to the query in the data source table, else you get undesired query results.
SELECT STATEMENT KEYWORDS

Some of the common SELECT statement keywords are:
1. THE “DISTINCT” KEYWORD:
If your data source field contains duplicate data and you want your query to return each of these duplicate data once, you add the DISTINCT keyword to your SELECT clause. For example, suppose you want your query your return distinct years from the order_year field of your order table, your SELECT clause should resemble this:
SELECT DISTINCT order.[order_date];

2. THE “AS”KEYWORD:
This is used for substituting names for field names or expression. You can change the label that is displayed for any field by using the AS keyword and a Field Alias.

A field alias is a name that you assign to a field in a query to make the result easier to read. For example, if you want your query to return data from the customer_phone field, which contains customer’s phone numbers, you can improve the readability of your query result by using a field alias in your SELECT statement as follows:
SELECT [customer_phone] AS [Customer Phone Number]

NOTE:
You must use a field alias when you use an expression in a SELECT clause.

USING A FUNCTION, AN EXPRESSION OR AN AGGREGATE FUNCTION AS AN IDENTIFIER IN A SELECT CLAUSE
Sometimes, you might want to retrieve only a part of a field’s data. For example, suppose that you want your query to return only the birth year of your customer’s from the birth_date field, then your SELECT clause might resemble this:
SELECT DatePart(“yyyy”, [birth_date]) AS [Birth Year]

This expression contains the DatePart function as an identifier and two arguments:
“yyyy” (a constant) and [Birth_date] (an identifier).

NOTES:
You can use any valid expression or function as an identifier in a SELECT clause provided it outputs a single value when given a single input value.

FROM CLAUSE:
Click http://www.microsofttut.com/2017/04/full-explanation-illustration-of-sql.html to study full post with screen to screen illustration.

(1) (Reply)

Learn Html,javascript,css And More Here / Top 10 Elements In App Ui Design You Should Know / Alphah Sales POS Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.