Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Union Query

Status
Not open for further replies.

nike2000

Technical User
Apr 1, 2003
61
GB
Hi,
Could you let me know what is wrong with this Union Query?
Thanks,

SELECT Bundlet_No, ReferenceEntity
FROM Tbl_Trades
WHERE (((ReferenceEntity) Is Not Null))
GROUP BY Tbl_Trades.Bundlet_No

UNION SELECT Bundlet_Mirror, Reference Entity
FROM Tbl_Trades
WHERE (((ReferenceEntity) Is Not Null))
GROUP BY Tbl_Trades.Bundlet_Mirror;
 
It depends on what you want this to do.

At a glance, it looks like something is missing. When you specify a 'GROUP BY', then you must either include the Reference Entity like so..

GROUP BY Tbl_Trades.Bundlet_Mirror, [Reference Entity];

which will remove any duplicates

or carry out some sort of aggregate function on Reference Entity, e.g.
SELECT Bundlet_No, COUNT([Reference Entity])
to return the number of Reference Entity fields



 
Are Bundlet_No and Bundlet_Mirror of same type (text or numeric) ?
And an unwanted space here:
Reference Entity

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for getting back to me guys.

What I am trying to do is merge the results of Bundlet_No and Bundlet_Mirror. But I would like to exclude all of the records that the Reference Entity is null.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top