473,666 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to understand Group By

Hi all... I have a quick question, if anyone knows the answer. I've
built a query which looks at a set of records in a table (tblFilename)
and I've set it up so that it displays the following fields:
filename, filedate, origin

Let me first explain the data - filename contains filenames, of which
there could be multiple items... filedate is the respective date stamp
from the filename listed... origin is the folder name where the file
is located.

My query takes the max of filedate, which (to my understanding) would
eliminate all of the other records that have multiple filedate records
(it would only keep the newest one), leaving me with a list of unique
filenames. This works - as long as I am only trying to get two fields
- filename and filedate. As soon as I add "origin" as another field
(it throws a "Group By" in the Total: section), I get all the records
in the table. It no longer tosses out the older dates. So my question
is - why does this happen? Shouldn't I be able to get the related
'origin' field information of the records that I'm keeping? Is it the
"Group By" that is causing my grief? Keep in mind that I'm staying
within the query builder - my SQL skills aren't too strong. However, I
HAVE tried adding DISTINCT to the select statement, but it doesn't
reduce the resulting records that my query produces.
Maybe I'm not explaining myself very well - I'm not entirely sure. If
anyone has an idea, could you please set me straight? Thanks!
-Terry

Jun 21 '06 #1
6 1894
sy****@gmail.co m wrote:
Hi all... I have a quick question, if anyone knows the answer. I've
built a query which looks at a set of records in a table (tblFilename)
and I've set it up so that it displays the following fields:
filename, filedate, origin

Let me first explain the data - filename contains filenames, of which
there could be multiple items... filedate is the respective date
stamp from the filename listed... origin is the folder name where
the file is located.

My query takes the max of filedate, which (to my understanding) would
eliminate all of the other records that have multiple filedate records
(it would only keep the newest one), leaving me with a list of unique
filenames. This works - as long as I am only trying to get two fields
- filename and filedate. As soon as I add "origin" as another field
(it throws a "Group By" in the Total: section), I get all the records
in the table. It no longer tosses out the older dates. So my
question is - why does this happen? Shouldn't I be able to get the
related 'origin' field information of the records that I'm keeping?
Is it the "Group By" that is causing my grief? Keep in mind that I'm
staying within the query builder - my SQL skills aren't too strong.
However, I HAVE tried adding DISTINCT to the select statement, but it
doesn't reduce the resulting records that my query produces.
Maybe I'm not explaining myself very well - I'm not entirely sure. If
anyone has an idea, could you please set me straight? Thanks!
-Terry


Max of filedate, group by filename

....returns the most recetn date for the unique values of filename.


Jun 21 '06 #2
sy****@gmail.co m wrote:
Hi all... I have a quick question, if anyone knows the answer. I've
built a query which looks at a set of records in a table (tblFilename)
and I've set it up so that it displays the following fields:
filename, filedate, origin

Let me first explain the data - filename contains filenames, of which
there could be multiple items... filedate is the respective date
stamp from the filename listed... origin is the folder name where
the file is located.

My query takes the max of filedate, which (to my understanding) would
eliminate all of the other records that have multiple filedate records
(it would only keep the newest one), leaving me with a list of unique
filenames. This works - as long as I am only trying to get two fields
- filename and filedate. As soon as I add "origin" as another field
(it throws a "Group By" in the Total: section), I get all the records
in the table. It no longer tosses out the older dates. So my
question is - why does this happen? Shouldn't I be able to get the
related 'origin' field information of the records that I'm keeping?
Is it the "Group By" that is causing my grief? Keep in mind that I'm
staying within the query builder - my SQL skills aren't too strong.
However, I HAVE tried adding DISTINCT to the select statement, but it
doesn't reduce the resulting records that my query produces.
Maybe I'm not explaining myself very well - I'm not entirely sure. If
anyone has an idea, could you please set me straight? Thanks!
-Terry


Max of filedate, group by filename

....returns the most recent date for the unique values of filename.
Max of filedate, group by filename and origin

....returns the most recent date for the unique combination of both values
filename and origin combined.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Jun 21 '06 #3

Rick Brandt wrote:

Max of filedate, group by filename

...returns the most recent date for the unique values of filename.
Max of filedate, group by filename and origin

...returns the most recent date for the unique combination of both values
filename and origin combined.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


Aaaahhh... Okay - I see the logic behind that part of it now. Thanks
for opening my eyes to that! However, is there a way that a person
could get the origin record for the records with latest date? (Pull
the Origin field with the rest of the query WITHOUT the Order By)?
Thanks for your reply, Rick! I appreciate it!

Jun 22 '06 #4
sy****@gmail.co m wrote:
Aaaahhh... Okay - I see the logic behind that part of it now. Thanks
for opening my eyes to that! However, is there a way that a person
could get the origin record for the records with latest date? (Pull
the Origin field with the rest of the query WITHOUT the Order By)?
Thanks for your reply, Rick! I appreciate it!


If you don't care which origin then you could replace that GroupBy with First,
Last, Min, or Max. If you want the same origin as the record with the last date
then you can use two queries. First create a query that gives the filename and
max(date) then feed that into a second query that also includes the original
table. Join the query to the table on the filename and filedate fields and then
bring down all three fields.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Jun 22 '06 #5
More FYI than anything, you could also a query with a nested subquery:
SELECT fnMain.FileName , fnMain.FileOrig in, fnMain.FileDate
FROM FileNames AS fnMain
WHERE (((fnMain.FileD ate)=(Select Max(FileDate) From FileNames as fnSub
Where fnSub.FileName = fnMain.FileName )));

Outside query selects name, origin, and file date.
Inner (or sub-) query finds the maximum file date for the file on a given
row.
The where clause links the two by comparing the filedate on each row to the
retrieved maximum filedate for the file on that row.

Rick Barndt's two queries will fun faster.
Jun 22 '06 #6
Thank you all so much for the information! I appreciate you taking the
time to explain that to me! The two queries worked fine, and I am
going to (for learning's sake) try out the subquery later today!
Everyone have a great day!
-Terry

Jun 22 '06 #7

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

Similar topics

1
1473
by: Vincent Jones | last post by:
I have this piece of script and I'm trying to understand what the 'SET t.Z_ASSOC_ROW = (t.rowid - m.MinRowID) + 1' and the 'INNER JOIN' line is doing UPDATE t SET t.Z_ASSOC_ROW = (t.rowid - m.MinRowID) + 1 FROM tassoc t INNER JOIN (SELECT Booking,MIN(rowid) AS 'MinRowID' FROM tassoc
4
1530
by: Danny | last post by:
I have this bit of code: SELECT itemcode, min(Price) AS minprice FROM itemlist GROUP BY itemcode; it lists the minimum price for each itemcode group. It works fine. But when I want to see the last name of the person who bought this item, it give me that aggregate error saying the lastname is not part of the aggregate function.
5
3773
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue as to what this means? I am not trying to alter a table. This particular CL merely generates the next voucher number in a sequence. "SQL0204: HRCU030P in HRZNCUSOBJ type *N not found. Cause . . . . . : HRCU030P in HRZNCUSOBJ type *N was...
1
1990
by: Learner | last post by:
Hi there, I have installed Sql server 2005 developer on my machine which already has a Sql server 2000 installed on. Now i am trying to query the Sqlserver 2005 data(Ex: from Person.Address located in AdventureWorks database) in Sqlserver 2000 query analyzer: When i try as Select * from Address it said invalid object. But when i explored AdventureWorks database in the Management studio i
13
1307
by: cj | last post by:
Stephany Young provided me with the following code to count threads created by my program. Public Class MyThreadCount Private Shared m_lock As New Object Private Shared m_threadcount As Int32 = 0 Public Shared Sub Increment() SyncLock (m_lock)
2
1980
by: badboybrown | last post by:
Hello folks, I found this piece of code on this group by Dorman Blackman: > Function BusinessDays(dDate1, dDate2) As Long > BusinessDays = (DateDiff("d", dDate1, dDate2) - _ > (DateDiff("ww", dDate1, dDate2) * 2) + 1) + _ > (WeekDay(dDate1) = vbSunday) + _ > (WeekDay(dDate2) = vbSaturday) > End Function
27
3841
by: jm | last post by:
I am having trouble understanding the purposes of an interface, even though the concept of interfaces is around me all the time (user interface, for example). I'm just not understanding software interfaces. Like anything else, it appears Interfaces are by design something that requires documentation. I know this may be obvious, but if I have a class A and I say, well, class A implements IMyInterface. The fact that it implements...
0
3222
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have given all the attributes which are needed, for the user, in the code and also the proper path where the user has to be added. Please have a look at my code CODE] // This is a class file which stores all the info required for the user
4
1474
by: GiuseppeDini | last post by:
I'm new to c++ and I'm trying to understand how libraries work with c+ +. I have a project (opencv, but this question is not opencv specific) with a folder for each library, and in each folder two folders "include" with headers and "code" with some headers and .cpp files. Furthermore there are two folders outside "bin" with .dll files and "lib" with .lib files. What I want to do is to produce .lib and .dll files by myself using my IDE...
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2771
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 we have to send another system
2
2011
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.