473,487 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

A2K - how do i make this SQL retrieve distinct values?



SELECT id, department FROM tblAssets UNION SELECT 0 AS id, "{All
departments}" AS department FROM tblAssets; UNION SELECT 0 AS id, "{All
departments}" AS department FROM tblAssets;

This gives me for example,
{All departments}
HI
ENG
ENG
I would like it to return only unique values so in the above results I
would like only 1 ENG.

I'm playing around with the SQL but not having much luck.

Many thanks again
Martin
Nov 13 '05 #1
3 2877
Use UNION ALL instead of just UNION - that gets rid of duplicates.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

Deano wrote:

SELECT id, department FROM tblAssets UNION SELECT 0 AS id, "{All
departments}" AS department FROM tblAssets; UNION SELECT 0 AS id, "{All
departments}" AS department FROM tblAssets;

This gives me for example,
{All departments}
HI
ENG
ENG
I would like it to return only unique values so in the above results I
would like only 1 ENG.

Nov 13 '05 #2
MGFoster wrote:
Use UNION ALL instead of just UNION - that gets rid of duplicates.


Cheers I gave that a go but it doesn't work. If I use ALL in both
places where a union keyword appears I get multiple occurrences....
Nov 13 '05 #3
Chuck Grimsby wrote:

In this example, YOU are putting in the duplicate value. You should
stop that. <Grin>

Assuming however, that the duplicates are comming from whatever tables
you are pulling from, you can use a grouping query inside your UNION
to eliminate the duplicates from the tables. The UNION query itself
will eliminate the duplicates.
oK thanks I will give that a go though I'm not sure about the syntax

If you are having duplicates, examine the fields very closely.
You'll probably discover that they aren't exactly the same. Access
can only eliminate duplicates that are exact matches (across the
entire row).


In case they are definitely the same. Hmm. I might first use a saved
query to produce the unique values and use THAT in the SQL - we shall
see...

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7408
by: Richard | last post by:
This is probably easy but I can't work it out. I have this statement SELECT DISTINCT TOP 100 PERCENT dbo.CIF_PlaceReference.Name FROM dbo.CIF_Departures INNER JOIN dbo.CIF_PlaceReference...
8
11083
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
3
1344
by: Lad | last post by:
Hi, I would like to make in my web application a similar navigation like Google uses, I mean at the bottom of each page there are numbers of returned pages after you search query. Has anyone...
3
1749
by: Trishia Rose | last post by:
God dang it all, i am so sick of programmers who feel compelled that every single time they use an int variable, they give it some brand new name! for example they would take an innocent function...
5
53331
by: Fred Zuckerman | last post by:
Can someone explain the difference between these 2 queries? "Select Distinct id, account, lastname, firstname from table1" and "Select DistinctRow id, account, lastname, firstname from table1" ...
7
4072
by: Johnathan Doe | last post by:
I can google search to find the range of values that can be represented in a float by reading up on the IEEE std, but is that the same as how many distinct values that can go in a float type? ...
5
6885
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has...
1
3495
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
3
1767
by: Yogesh Sharma | last post by:
I want to select that rollnos which have distinct name & address. create table studento(roll int,name varchar,address varchar(5)) insert into studento values(1,'A','ADD1') insert into studento...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.