473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Using DISTINCT in a WHERE Clause

489 256MB
To save some code I would like to put a distinct clause in the criteria for a report. I've created a table that I'm using for multiple reports but in some of the reports I only need one instance of a record but need multiples of that record in other reports. I'm using the same report layout with 7 different criteria's. So is there a way to put a distinct clause or some other statement that would select only unique records in a where clause(criteria)
I hope this makes some sense
Jan 6 '18 #1

✓ answered by NeoPa

DISTINCT is a keyword used in the SELECT clause only. It cannot be used in the WHERE clause as that would make absolutely no sense. You could use a GROUP BY clause and have similar results but it wouldn't be exactly the same thing.

Are you thinking about using a filter string?

3 2033
NeoPa
32,556 Expert Mod 16PB
DISTINCT is a keyword used in the SELECT clause only. It cannot be used in the WHERE clause as that would make absolutely no sense. You could use a GROUP BY clause and have similar results but it wouldn't be exactly the same thing.

Are you thinking about using a filter string?
Jan 7 '18 #2
CD Tom
489 256MB
No I'm not thinking of a filter. I'm thinking that I will create a couple of queries one with the distinct. I'll create them in the program in the section before I print the reports.
Jan 7 '18 #3
NeoPa
32,556 Expert Mod 16PB
In that case you should now have all the information you need.

Be aware there are two related keywords :
DISTINCT
DISTINCTROW

The first applies only to the fields SELECTed whereas the second applies to the whole row regardless of which fields are used.
Jan 7 '18 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jacek | last post by:
Hi, can anyone shed some light on this issue? SELECT Status from lupStatus with a normal query it returns the correct recordcount SELECT Status from lupStatus GROUP BY Status but with a GROUP...
2
by: MasterChief | last post by:
I have a Drop Down box that is being populated using the SQL Distinct command. How do I get it so it doesn't show Null values? Here is my SQL statement sSQL = "SELECT DISTINCT Title FROM...
4
by: Johnson, Shaunn | last post by:
Howdy: Can someone tell what the difference (and why you would use it) is between the following: select distinct on (col_1, col_2), col_1, col_2, col_3
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
1
by: Patrick.O.Ige | last post by:
I'm trying to do distinct below in a datatable but i get the error :- Syntax error: Missing operand after 'Code' operator. Any ideas? string strExpr = "DISTINCT Code LIKE '%ve%'" ; DataRow...
4
by: osmarjunior | last post by:
Hi. I made a method to execute queries in my database (Firebird embedded v.1.5.3). The Database class contains methods to create the database specific objects. public static DbDataReader...
8
by: bnashenas1984 | last post by:
I'm using DISTINCT to get one of each title out of my table. Here is my table: +---------------------------+ | title | weather | +---------------------------+ | Monday | ...
4
by: omnittha | last post by:
I would like to pull unique records of a SINGLE column but not the other related columns. When I use DISTINCT, it pulls up all the records which are unique across the columns. Here is the code.......
1
Gyanchand
by: Gyanchand | last post by:
I have recently migrated DB from Sql Server 2000 to Sql Server 2005. Ever since, when i fire queries with a DISTINCT clause, the recordcount property returns the result as -1. I am using the...
0
by: Rameshk | last post by:
Can we define an Incremental MQT having clause COUNT(DISTINCT..)??? I am facing the issue while creating the Staging Table for one of the MQTs which has this clause in it's definition.I am able to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.