Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,363 members, 7,808,269 topics. Date: Thursday, 25 April 2024 at 09:38 AM

Real Life Illustrations Of Sql In Ms Access & Mysql - Union & Join Queries - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Real Life Illustrations Of Sql In Ms Access & Mysql - Union & Join Queries (1027 Views)

Guide To Create Join Queries In Ms Access & Mysql– Object Joins Or Relationships / Study Explanations & Illustrations Of Sql Clauses & Keywords In Ms Acess & Mysql / Sql Tutorial Training In Ms Access & Mysql Databases – Step By Step Guide (2) (3) (4)

(1) (Reply)

Real Life Illustrations Of Sql In Ms Access & Mysql - Union & Join Queries by microsofttutor(m): 10:57pm On Apr 08, 2017
I have been so theoretical since the introduction of this SQL chapter for MS Access and MySQL Databases. Now let me show you the real life or practical, real life and business applications of SQL (Structured Query Language) that I have been explaining. I will apply SQL to build these two types of advanced query in MS Access and MySQL databases, namely:
1. THE UNION QUERY
2. THE QUERY JOIN

THE UNION QUERY:
This just like the table relationship/join I explained in chapter 2. This query lets you combine the results returned by two SELECT statements or queries and displays them as one result. In table join, MS Access does all the underground work for you. All you just did then was to click and Access generates the SQL statements without your knowledge. But now, you will generate everything from the scratch. That is what makes it an advanced query.

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

In the previous part (Part 2) at http://www.microsofttut.com/2017/04/full-explanation-illustration-of-sql.html, I explained all SQL clauses and Keywords in MS Access and MySQL in detail. Also see the full tutorial course content of this Microsoft Excel Tutorial Series at http://www.microsofttut.com/p/microsoft.html.

NOTES:
The UNION query joins two or more SELECT queries together, also, the SELECT statements that you combine in a union query must have the same number of output fields in the same order and with the same or compatible data types.

Also note that the Text data type and the Number data type are compatible for the purpose of union query.

You have to switch to the SQL view in MS Access to create a union query because a union query is SQL –specific.

The basic SQL syntax for a union query that combines two SELECT query is:

SELECT [field_1], [field_2],… FROM [table_1], [Table_2],…
UNION ALL
SELECT [field_a], [field_b],… FROM [table_a], [Table_b],…

NOTE:

The ALL keyword is optional. When you use the ALL keyword, duplicate rows are not removed from the combined set that is produced by the UNION query. You can also use it when you are sure that the SELECT statements will not produce any duplicate rows or if you want to see duplicate rows.

The UNION keyword combines the results returned by two SELECT statements or queries and displays them as one result.

HOW TO CREATE A UNION QUERY IN MS ACCESS
There are two basic methods of creating UNION queries in Microsoft Access:
1. Combining two SELECT queries previously created in Query Design view
2. Creating the UNION query directly in SQL view

COMBINING TWO SELECT QUERIES PREVIOUSLY CREATED IN QUERY DESIGN VIEW
This method becomes the alternative if you have previously created the two SELECT queries and then wish to combine or merge their results.

For example, as an Administrative Head of a University, you might want to merge or join two queries named old students record and new students record to form one query. Since you already have the two queries available, you will use this alternative to create the JOIN query.

To Combine Two Previously Created SELECT Queries Using the UNION Keyword:
1. Open the first SELECT query in SQL view and copy the SQL statement. Referring to the above example, I will first open the new students records SELECT query in SQL view and copy the SQL statement as shown below.

Click http://www.microsofttut.com/2017/04/practical-application-of-sql-in-ms-access-mysql.html to study full post with screen to screen images.

(1) (Reply)

Want To Be A Programmer / 15 Web Developers Needed At Digital Dreams Limited / Get these Tools only here

(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. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.