473,770 Members | 4,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do UNION queries inherently force UNIQUE records by their own nature?

MLH
Consider having tblCorresponden ce, then copying & pasting
it to tblCorresponden ce1 - such that they are identical. Then
consider the following UNION SELECT statement...

SELECT tblCorresponden ce.CorrespID, tblCorresponden ce.VehicleJobID ,
tblCorresponden ce.OutDate, tblCorresponden ce.OutType,
tblCorresponden ce.OutProcessor , tblCorresponden ce.InDate,
tblCorresponden ce.InRefDate, tblCorresponden ce.InType,
tblCorresponden ce.InProcessor, tblCorresponden ce.ToWhom,
tblCorresponden ce.CorrespTDSta mp, tblCorresponden ce.UserID,
tblCorresponden ce.Tracked
FROM tblCorresponden ce
WHERE (((tblCorrespon dence.VehicleJo bID)=901) AND
((tblCorrespond ence.OutType)=" 00"))

UNION SELECT tblCorresponden ce1.CorrespID,
tblCorresponden ce1.VehicleJobI D, tblCorresponden ce1.OutDate,
tblCorresponden ce1.OutType, tblCorresponden ce1.OutProcesso r,
tblCorresponden ce1.InDate, tblCorresponden ce1.InRefDate,
tblCorresponden ce1.InType, tblCorresponden ce1.InProcessor ,
tblCorresponden ce1.ToWhom, tblCorresponden ce1.CorrespTDSt amp,
tblCorresponden ce1.UserID, tblCorresponden ce1.Tracked
FROM tblCorresponden ce1
WHERE (((tblCorrespon dence1.VehicleJ obID)=901) AND
((tblCorrespond ence1.OutType)= "00"));

Knowing full well that both tables contain 1 record meeting the
specified criteria (record ID #69203) - why do I see only a single
row in the query output?

If I change the criteria specified for tblCorresponden ce1 to
WHERE (((tblCorrespon dence1.VehicleJ obID)=902) AND
((tblCorrespond ence1.OutType)= "00")); (replacing 901 with 902)
I see 2 rows in the output. I'm not saying I have a fruitful purpose
for pulling the same record number from 2 identical tables

I even tried the following. I still get the same results - a single
record in the output. Anybody know why?

SELECT tblCorresponden ce.CorrespID AS ONE,
tblCorresponden ce.VehicleJobID AS TWO, tblCorresponden ce.OutDate AS
THREE, tblCorresponden ce.OutType AS FOUR,
tblCorresponden ce.OutProcessor AS FIVE, tblCorresponden ce.InDate AS
SIX, tblCorresponden ce.InRefDate AS SEVEN, tblCorresponden ce.InType AS
EIGHT, tblCorresponden ce.InProcessor AS NINE, tblCorresponden ce.ToWhom
AS TEN, tblCorresponden ce.CorrespTDSta mp AS ELEVEN,
tblCorresponden ce.UserID AS TWELVE, tblCorresponden ce.Tracked AS
THIRTEEN
FROM tblCorresponden ce
WHERE (((tblCorrespon dence.VehicleJo bID)=901) AND
((tblCorrespond ence.OutType)=" 00"))

UNION SELECT tblCorresponden ce1.CorrespID AS ONE,
tblCorresponden ce1.VehicleJobI D AS TWO, tblCorresponden ce1.OutDate AS
THREE, tblCorresponden ce1.OutType AS FOUR,
tblCorresponden ce1.OutProcesso r AS FIVE, tblCorresponden ce1.InDate AS
SIX, tblCorresponden ce1.InRefDate AS SEVEN, tblCorresponden ce1.InType
AS EIGHT, tblCorresponden ce1.InProcessor AS NINE,
tblCorresponden ce1.ToWhom AS TEN, tblCorresponden ce1.CorrespTDSt amp AS
ELEVEN, tblCorresponden ce1.UserID AS TWELVE,
tblCorresponden ce1.Tracked AS THIRTEEN
FROM tblCorresponden ce1
WHERE (((tblCorrespon dence1.VehicleJ obID)=901) AND
((tblCorrespond ence1.OutType)= "00"));

Jan 27 '08 #1
2 2255
MLH <CR**@NorthStat e.netwrote in
news:68******** *************** *********@4ax.c om:
Consider having tblCorresponden ce, then copying & pasting
it to tblCorresponden ce1 - such that they are identical. Then
consider the following UNION SELECT statement...

Knowing full well that both tables contain 1 record meeting the
specified criteria (record ID #69203) - why do I see only a single
row in the query output?

If I change the criteria specified for tblCorresponden ce1 to
WHERE (((tblCorrespon dence1.VehicleJ obID)=902) AND
((tblCorrespond ence1.OutType)= "00")); (replacing 901 with 902)
I see 2 rows in the output. I'm not saying I have a fruitful
vpurpose
for pulling the same record number from 2 identical tables

I even tried the following. I still get the same results -
single
record in the output. Anybody know why?
The drafters of the SQL language figured correctly that the
majourity of UNION queries would use the DISTINCT Clause, so that is
what is the default, contrary to a normal SELECT query has ALL as
the default.

Like most languages, not specifying ALL|DISTINCT results in the
default being applied.

Override the default? Just add the ALL Keyword after the UNION
SELECT statement.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jan 27 '08 #2
MLH
Cool. Many thx.
Jan 28 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
12843
by: KENNY L. CHEN | last post by:
Dear experts, I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO). Both tables are unique-indexed on (COL1,COL2,REC_NO). I think the following SQL commands will return the same result but one of my friends don't think so. He said "QUERY 1" will return 1 unsorted record (ROWNUM < 2 ) first then sort the result (ORDER BY COL1 ASC,
2
3832
by: Fred Zuckerman | last post by:
I have a union query joining two other queries, each with 62 fields. Interestingly, when I open the query it has the correct number of 2850 records. But if I then set a filter (using filter by form), when I apply the filter I get only 206 records, when I should get 208. If I then remove the filter I get 2850 records again. But if I then click on "apply filter" again I get only 186 records. Each time I remove the filter I get the...
2
2284
by: M Stery | last post by:
Have two base queries used for mailing labels with id,name,address,city,state,zip that are combined via a union query. One base query uses home address; the other base query uses biz address. I only want one label per person. In a few cases, I have a record with both a home address and a biz address, which I don't want in the labels. How or can I make the union query omit an id in the biz address base query IF that same id has a record in...
5
1922
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
1
7778
by: CrystalDBA | last post by:
I usually design applications in SQL Server and Crystal Reports. I now need to create a crystal report on an MS Access database. I have two tables: Services: Date datetime Entry text Amount number (should be 4 records)
2
4342
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code Count 1234 1 2468 1 1234 1 2468 1
12
2915
by: Susan Bricker | last post by:
For those of you who have been following my posts - they all pertain to a Dog Competition Organization's Database. There are three classes that the dogs can participate: NOVICE, OPEN, and UTILITY. I want to produce a report of the top 10 average scores for each class for each year.
5
2281
by: BillCo | last post by:
I'm having a problem with a union query, two simple queries joined with a union statement. It's created in code based on parameters. Users were noticing some inconsistant data and when I analysed the query produced and opened it from a MS Query it started giving strange results. The first query when run alone returns 22 records, some of which have identical values in all fields. This is 100% correct. The second query returns nothing....
0
1144
by: ticktack | last post by:
Hi there, I am trying to do a UNION with slightly different queries, it appears to work but it now bring in another problem. The second part of the UNION need to have a an extra field value ("NULL") added thus to match the number of fields between the two select queries. The problem comes that I some have duplicate records and want to condense them down so that "Table_Form_Element_ID" has a single record against it but I want the record to be...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.