Are you certain that what you posted is the SQL you're actually using?
You
didn't accidentally put UNION ALL instead of just UNION, did you?
UNION eliminates duplicates: UNION ALL doesn't.
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Mr. B,
I still can't get this working correctly. the table has 10 records, all
text:
freemach
freemach
mannalie
mannalie
mannalie
mannalie
freemach
freemach
tragarzb
tragarzb
What I'm looking for is a drop down that looks like this:
________
ALL
freemach
mannalie
tragarzb
________
Your first statement resulted in the drop down being completely blank,
not
even the "ALL" displayed.
Your second statement resulted in error: Syntax error (missing
operator)
in
query expression ""0"". So I removed one set of qoutes, around the 0,
like
this "0", and this results in returning a drop down with ALL and all of
the
records.
Then I thought that because of the Used_ID field is unique, an
autonumber,
this brings back unique records, and thereby duplicate UserName values.
So
first I removed User_ID, but this errored out. then I switched User_ID
and
UserName places in the statement, but this resulted in all the User_IDs
displaying in the drop down.
So next removed the User_ID tag, and this resulted in an error: "The
number
of columns in the two selected tables or queries of a union query do
not
match."
So from here I thought I would remove the "0" as bogus and that left me
with: "...UNION select "All" from tbl_User_Login...". unfortunately,
this
left me with no error, but an empty drop down menu, no ALL, no values.
I have used this Union for adding "ALL" before, but now realize that
those
were always on non-duplicated records. this is tunring into a real hair
puller.
--
Chris Freeman
IT Project Coordinator
:
Chirs,
There is quite a difference between the two sql statements that you
refer
to. In the first one:
SELECT "ALL" as UserName FROM tbl_User_Login UNION SELECT DISTINCT
tbl_User_Login.UserName FROM tbl_User_Login order by [UserName] asc;
You are attempting to only return a unique list of the values from the
UserName field and have the "All" option also available but you have
started
with the "All" part. If this is really what you are wanting try this:
SELECT DISTINCT tbl_User_Login.UserName
FROM tbl_User_Login UNION select "All" from tbl_User_Login
ORDER BY tbl_User_Login.UserName;
In the last sql statement you are asking for unique records and
including
what I assume is a unique value field (USER_ID). You did not indicate
what
type of field that the USER_ID field is. If this is an autonumber
field
the
you will get every record because that field would make each recrod
unique.
If this field is an auto number type field try this:
SELECT DISTINCTROW tbl_User_Login.USER_ID, tbl_User_Login.UserName
FROM
tbl_User_Login UNION select 0 as bogus, "All" from tbl_User_Login
ORDER BY tbl_User_Login.UserName;
If the USER_ID field is a text type field you will need to enclose the
zero
in quotes, like this:
SELECT DISTINCTROW tbl_User_Login.USER_ID, tbl_User_Login.UserName
FROM
tbl_User_Login UNION select ""0"" as bogus, "All" from tbl_User_Login
ORDER BY tbl_User_Login.UserName;
-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
:
to all,
I have a drop down and I want to add "ALL" to the head of the list.
I
found
some code from a 2007 post:
SELECT "ALL" as UserName FROM tbl_User_Login UNION SELECT DISTINCT
tbl_User_Login.UserName FROM tbl_User_Login order by [UserName]
asc;
But in doing so, I show only the 'ALL' and the rest of the spaces
are
blank.
There are 10 records to be returned, and the drop down has one ALL
and
10
blank rows. This is the code I'm using currently, but it references
a
static
table and shows repeating entries:
SELECT tbl_User_Login.USER_ID, tbl_User_Login.UserName FROM
tbl_User_Login
UNION SELECT DISTINCT 'ALL','ALL' FROM tbl_User_Login order by
[UserName]
ASC;
Any ideas what I'm doing wrong? I just want an DITINCT record return
with
ALL at the top.