473,563 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tough query problem

12 New Member
hey all,

i am having a problem with a certain query which pulls records from two tables. one table contains info entered into a main form, and the other has information entered into the subform.

what i want the query to pull is all the records from the main table, and only the most recent record (IE latest date inputed into "date" field) from the sub table.

however what ends up happening is the query will pull all the records from the subtable. so instead of having say 5 records from the main form and 5 from the subform, i get 5 records from the main form but 20-30 from the subform!

does anyone know how to fix this
Jun 7 '07 #1
5 1476
Rabbit
12,516 Recognized Expert Moderator MVP
Try using a subquery in the date criteria.
Jun 7 '07 #2
jconstan
12 New Member
eh thanks for the response, i have been trying to do the subquery, but i cant seem to figure it out :S do i have to create a seperate query? or just an expression in the criteria field?

thanks again.
Jun 8 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. SELECT x.*
  2. FROM Table1 As x
  3. WHERE x.SomeDate = (SELECT Max(SomeDate) As Expr1
  4.                     FROM Table1;)
  5. ;
  6.  
Jun 8 '07 #4
jconstan
12 New Member
k so i used your technique and here is the code:

SELECT [Project Management].[Project Name], [Project Management].[Assigned to], [Project Management].[Implementation Start Date], [Status Updates Sub].Status, [Status Updates Sub].Date
FROM [Project Management] INNER JOIN [Status Updates Sub] ON [Project Management].ID = [Status Updates Sub].ID
WHERE ((([Status Updates Sub].Date)=(SELECT Max(Date) AS Expr1 FROM [Status Updates Sub];)))
GROUP BY [Project Management].[Project Name], [Project Management].[Assigned to], [Project Management].[Implementation Start Date], [Status Updates Sub].Status, [Status Updates Sub].Date, [Status Updates Sub].ID;

however, it is only taking the first record from the main form now. but what i need is every record from the main form and just one record from the subform (for each record in the main form)
Jun 8 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. SELECT x.*
  2. FROM Table1 As x
  3. WHERE x.SomeDate = (SELECT Max(SomeDate) As Expr1
  4.                     FROM Table1
  5.                     WHERE KeyField= x.KeyField;)
  6. ;
  7.  
I forgot to include a way to link the subquery to the main query.

But aside from that, why do you even have groupings? You have no need for them.
Jun 8 '07 #6

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

Similar topics

4
2265
by: leegold2 | last post by:
Let's I do a mysql query and then I do a, for( $i = 1; $row = mysql_fetch_array($result); $i++ ) {...} and it gives me this: PageID Title URL Description 1 lee's gogle1.com This is lee's website. 1 lee's gogle2.com This is lee's website. 2 Jon's yaho1.com This is Jon's...
6
1983
by: Matt Creely | last post by:
I have a very strange database with a very strange problem. Consider 4 tables: Table1: ---------------- Table1ID INT PK Table2ID INT FK Table3ID INT FK OrderNo VARCHAR(50)
3
2591
by: Roman | last post by:
I've been trying this one for 2-3 hours and can't figure it out. I'de appreciate any help or pointers in the right direction. Thanks. Query I need the query to return me all the lottery names and results that have the latest date in the database for that particular game and for the state . So the return data from the data below data would...
198
11405
by: Sy Borg | last post by:
Hello: We are designing two multi-user client server applications that performs large number of transactions on database servers. On an average Application A has a 50% mix of select and update/insert/delete statements and application B has 80-20 mix of select and update/insert/delete statements. Being able to scale the databases as needed...
2
1030
by: Prince | last post by:
I have a major problem. I have an entire HTML page stored within a string variable. ex. <html><head><title>text</title></head> <body> some data </body> </html>
28
3897
by: Arial | last post by:
My SQL string is kind of wierd one. In my application, I need to select things from an unknown name table. But I know the table name before the SQL command is executed. For instance, Dim varname as string = 'one of my variable. It's part of the table name. Dim t1 as String = varname+ "0000"
12
2724
by: Bill Bob | last post by:
I am going mad with this Query. I need to join 3 Tables. Their Formats are Vouchers NOT NULL , NOT NULL , NULL , NOT NULL , (255) CONSTRAINT PRIMARY KEY CLUSTERED
7
2248
by: Dan | last post by:
I am trying to create a query (in either sql or the design view) to determine which two (or more I suppose if it's not too complicated) baseball players were teammates the longest. The database includes the following fields: YearId, PlayerId, and teamId. I have been unable to write query that can caluclate the number of years players would...
5
2227
by: steven.fafel | last post by:
I am running 2 versions of a correlated subquery. The two version differ slightly in design but differ tremendously in performance....if anyone can answer this, you would be awesome. The "bad" query attempts to build a result set using a correlated subquery. The part causing the error is that the correlated subquery is part of a derived...
0
7665
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...
0
8106
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...
1
7642
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...
0
7950
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...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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

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.