A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can't see what is wrong with this Union query...



 
 
Thread Tools Display Modes
  #1  
Old April 27th, 2010, 11:26 PM posted to microsoft.public.access.queries
AndyK
external usenet poster
 
Posts: 19
Default Can't see what is wrong with this Union query...

Can you?

SELECT "Fred" AS Name FROM tblMonths
UNION ALL SELECT "Joe" AS Name FROM tblMonths;

  #2  
Old April 27th, 2010, 11:36 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Can't see what is wrong with this Union query...

Your union query is not required to pull any data from the table.
Maybe you want something like this that does not need a union query --

SELECT tblMonths.*
FROM tblMonths
WHERE Name = "Joe" OR Name = "Fred";

--
Build a little, test a little.


"AndyK" wrote:

Can you?

SELECT "Fred" AS Name FROM tblMonths
UNION ALL SELECT "Joe" AS Name FROM tblMonths;

  #3  
Old April 28th, 2010, 12:42 AM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Can't see what is wrong with this Union query...

AndyK wrote:
Can you?

SELECT "Fred" AS Name FROM tblMonths
UNION ALL SELECT "Joe" AS Name FROM tblMonths;


Is the idea to get 12 rows with "Fred" in them and 12 with "Joe"?

The only possible issue I see is using the reserved keyword "Name" as your
column alias (btw, you only need to use the alias in the first query - the
rest of the queries in a union take the column names from the first query).
Perhaps it would help if you clued us in on whatever symptom is making you
think there is something "wrong" with this query. We're not psychics, you
know :-)

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #4  
Old April 28th, 2010, 09:15 AM posted to microsoft.public.access.queries
AndyK
external usenet poster
 
Posts: 19
Default Can't see what is wrong with this Union query...

Bob thanks for the response, agree re complete lack of information from me!

OK - I am after two rows and one column of output which looks like

Fred
Joe

All my data will be literal - I am only using tblMonths as I believe I have
to quote some table or query as input even if as in this case none of my data
is in it.

Have this morning discovered that this works fine in Access 2007 but my
problem is with Access 2003 - this is my target version. In 2003 it returns
no data....?

Thanks for any further input.

"Bob Barrows" wrote:

AndyK wrote:
Can you?

SELECT "Fred" AS Name FROM tblMonths
UNION ALL SELECT "Joe" AS Name FROM tblMonths;


Is the idea to get 12 rows with "Fred" in them and 12 with "Joe"?

The only possible issue I see is using the reserved keyword "Name" as your
column alias (btw, you only need to use the alias in the first query - the
rest of the queries in a union take the column names from the first query).
Perhaps it would help if you clued us in on whatever symptom is making you
think there is something "wrong" with this query. We're not psychics, you
know :-)

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.

  #5  
Old April 28th, 2010, 12:09 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default Can't see what is wrong with this Union query...

Is there at least one record in tblMonths? There needs to be a record if the
query is going to return anything.

AndyK wrote:
Bob thanks for the response, agree re complete lack of information
from me!

OK - I am after two rows and one column of output which looks like

Fred
Joe

All my data will be literal - I am only using tblMonths as I believe
I have to quote some table or query as input even if as in this case
none of my data is in it.

Have this morning discovered that this works fine in Access 2007 but
my problem is with Access 2003 - this is my target version. In 2003
it returns no data....?

Thanks for any further input.

"Bob Barrows" wrote:

AndyK wrote:
Can you?

SELECT "Fred" AS Name FROM tblMonths
UNION ALL SELECT "Joe" AS Name FROM tblMonths;


Is the idea to get 12 rows with "Fred" in them and 12 with "Joe"?

The only possible issue I see is using the reserved keyword "Name"
as your column alias (btw, you only need to use the alias in the
first query - the rest of the queries in a union take the column
names from the first query). Perhaps it would help if you clued us
in on whatever symptom is making you think there is something
"wrong" with this query. We're not psychics, you know :-)

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"


.


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #6  
Old April 30th, 2010, 11:31 PM posted to microsoft.public.access.queries
AndyK
external usenet poster
 
Posts: 19
Default Can't see what is wrong with this Union query...

Bob

You are spot on, I added a record to tblMonths and it works - thank you!

"Bob Barrows" wrote:

Is there at least one record in tblMonths? There needs to be a record if the
query is going to return anything.

AndyK wrote:
Bob thanks for the response, agree re complete lack of information
from me!

OK - I am after two rows and one column of output which looks like

Fred
Joe

All my data will be literal - I am only using tblMonths as I believe
I have to quote some table or query as input even if as in this case
none of my data is in it.

Have this morning discovered that this works fine in Access 2007 but
my problem is with Access 2003 - this is my target version. In 2003
it returns no data....?

Thanks for any further input.

"Bob Barrows" wrote:

AndyK wrote:
Can you?

SELECT "Fred" AS Name FROM tblMonths
UNION ALL SELECT "Joe" AS Name FROM tblMonths;

Is the idea to get 12 rows with "Fred" in them and 12 with "Joe"?

The only possible issue I see is using the reserved keyword "Name"
as your column alias (btw, you only need to use the alias in the
first query - the rest of the queries in a union take the column
names from the first query). Perhaps it would help if you clued us
in on whatever symptom is making you think there is something
"wrong" with this query. We're not psychics, you know :-)

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"


.


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.