PC Review


Reply
Thread Tools Rate Thread

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

 
 
AndyK
Guest
Posts: n/a
 
      27th Apr 2010
Can you?

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

 
Reply With Quote
 
 
 
 
KARL DEWEY
Guest
Posts: n/a
 
      27th Apr 2010
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;
>

 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      28th Apr 2010
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"


 
Reply With Quote
 
AndyK
Guest
Posts: n/a
 
      28th Apr 2010
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"
>
>
> .
>

 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      28th Apr 2010
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"


 
Reply With Quote
 
AndyK
Guest
Posts: n/a
 
      30th Apr 2010
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"
>
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter Query Based on Form Input within a Union Query =?Utf-8?B?amJyaWNrZXlAdW5rbm93bnNpdGUuY29t?= Microsoft Access Queries 2 6th Sep 2007 03:12 PM
UNION or UNION ALL query question Olga Microsoft Access Queries 2 6th Apr 2006 08:49 PM
how could i default a value in a multi union query if the query didn't have value to return?? Tracy Microsoft Access 3 14th Jan 2006 12:12 AM
Form input in query, Union and crosstab query gives error msg Christian Microsoft Access Queries 2 17th Nov 2004 05:00 PM
query with criteria promt will not carry forward after a union query Brooks Friend Microsoft Access Queries 0 31st Jul 2003 10:44 PM


Features
 

Advertising
 

Newsgroups
 


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