Help with SQL Union All Query

andream02

Board Regular
Joined
Jul 26, 2007
Messages
70
Hello,

I'm working with a Union All Query and I'm not quite sure I understand what exactly the query is doing.

I understand the query until I get to the union all, after that, I'm a bit lost. This may be a very simple query, but I'm not sure I understand its intent.

Below is the SQL:

SELECT Users.ID, Profiles.NAME, Users.NAME
FROM Users INNER JOIN Profiles ON Users.PROFILEID = Profiles.ID
WHERE (((Profiles.NAME)="Marketing User")) OR (((Users.NAME)="Bob Smith")) OR (((Users.NAME)="Bill Evans"));


UNION ALL select "00G70000001L9JCEA0", "Marketing User", "Queue" from [Utility_Date] where Utility_Date.date=date();

When I run the second query on it's own, it appears that the query is just taking "00G70000001L9JCEA0", "Marketing User", "Queue" as expressions where there is a match on the date. When I go back through the User and Profile tables, I do not find any records with the ID# above. Does this mean that if it can't identify the Profile as Marketing User, Bob Smith or Bill Evans from the Profile and User tables, that it will assign it to "Queue"?

I'm afraid I'm not as well versed in interpreting this. I'm just confused and would appreciate any help you could provide.

Thanks!

Andrea
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
UNION ALL should add all records returned from the second query to the results of the first, regardless of duplicates between the sets.
 
Last edited:
Upvote 0
Give some examples of your data and what you want the results of the query to be. It's not entirely clear what you are aiming at with this query (I'm not even sure that a union query is the right type of query to use here).
 
Upvote 0
Hi Xenou, unfortunately, I've inherited this query from someone who is the role before me. So I'm just as puzzled as to why a union all was used here. But after doing some additional testing last night, it appears that my predecessor used the union all to add the user "Queue" to the list of users since "Queue" is not in the original data set.

It took me a while, but I think I understand now.

Thank you for your help!

Andrea
 
Upvote 0
Okay. No problem. That makes sense.
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,913
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top