I have two tables:
table1:
number explanation
10 something here
11 something here
12 something here
13 something here
14 something here
20 something here
24 something here
45 something here
122 something here
table 2:
number results
10 something here
10 something here *
11 something here
11 something here *
12 something here *
14 something here *
24 something here
24 something here *
I want to have a SELECT query to return all "number"s and all "explanation"s from table1 and the last "result" of each "number" in table2 (the ones I put * next to are the ones I want) (the *s are not actually in the table, I have put them here to show which records I want)
note that some "numbers" appear only once in table 2 and some others apprear twice.
this is what I want:
number explanation results
10 something here something here
11 something here something here
12 something here something here
13 something here
14 something here something here
20 something here
24 something here something here
45 something here
122 something here
8 5193
Hello. - Leftjoin table1 with table2.
- Grouping query on that join to return "last" record per group.
Dear FishVal,
Thanx for your reply. I am not an expert developer. Please provide more details. I honestly did not undrestand.
I know how to do the left-join part, but nothing about the grouping...
And one important thing I forgot to say is that there is also a unique numbering field in table1 (autonumber)
Perhaps this field can be helpful
Thanx a lot
You can find more details in Access help concerning "GROUP BY Clause".
NeoPa 32,556
Expert Mod 16PB
Try : - SELECT Table1.Number,
-
Table1.Explanation,
-
Last(Table2.Results) AS LastResults
-
-
FROM Table1 LEFT JOIN Table2
-
ON Table1.Number=Table2.Number
-
-
GROUP BY Table1.Number,
-
Table1.Explanation
-
-
ORDER BY Table1.Number
When searching Access Help for SQL related issues, navigate to a top-level entry including "Microsoft Jet SQL" from the Table of Contents.
Dear NeoPa,
Thank you so so so so so so much for your reply. I am not yet getting the results I want, because it is the Last of each "number" in Table2 that I want to see the "result" for. The "result" field sometimes is null, so if I try the "Last" thing on the result, I will get the previous record, in which the "result" is not null.
I have made a simple database with only the two tables I am working on. The database is attached. Please be kind enough to take a look at the tables, and see if you can help me with this query.
In Table2 of the attached database, the records with uniquenumbers 302, 304, 306, 307, 309, 311, 312, 313 and 314 are the ones I want.
Thank you very very very very much.
NeoPa 32,556
Expert Mod 16PB
It seems that all aggregate functions (Count, Last, Sum, etc) ignore Null entries. This is usually good, but in your case it causes a problem. We will either need to use theAutoNumber field to resolve this or create an extra TimeStamp field. I will have another look later.
PS. I'm really pleased you created that database of just what was needed. That's exactly how it SHOULD be done :)
Something like the following:
Query: qryT1LJT2 -
SELECT Table1.*, Table2.*
-
FROM Table1 LEFT JOIN Table2 ON Table1.Number = Table2.Number;
-
Query: qryLastRecordsUIDs -
SELECT qryT1LJT2.Table1.Number, Max(qryT1LJT2.uniquenumber) AS LastRecordUID
-
FROM qryT1LJT2
-
GROUP BY qryT1LJT2.Table1.Number;
-
Query: qryT1WithT2UID -
SELECT Table1.*, qryLastRecordsUIDs.LastRecordUID
-
FROM qryLastRecordsUIDs INNER JOIN Table1 ON qryLastRecordsUIDs.Number = Table1.Number;
-
Query: qryFinal -
SELECT qryT1WithT2UID.*, Table2.Results1, Table2.Results2
-
FROM qryT1WithT2UID LEFT JOIN Table2 ON qryT1WithT2UID.LastRecordUID = Table2.uniquenumber;
-
Regards,
Fish
Dear FishVal and Neopa,
Thank you very much for your kind help.
I figured it out this way:
first, making a query which selects the LAST of "Numbers" in Table2
Then, making another query, which LEFT JOINs all the Numbers in Table 1 with the ones already selected by the first query.
Thank you so much.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dan Matthews |
last post by:
Hey everybody,
I have an 2000 Access database that stores job listings from potential
employers for a school. I would like to be able to display the date
on a webpage the last time the database...
|
by: adam |
last post by:
hello
I have strange problem.
I write to MySQL data to table with one column of varchar(8000). I write
750000 bytes, so it get 93 records of 8000 bytes and the last - 6000bytes.
but what is...
|
by: William Wisnieski |
last post by:
Hello Everyone,
I have a main form with a datasheet subform that I use to query by form.
After the user selects two criteria on the main form and clicks the
cmdShowResults button on the main...
|
by: Chris Plowman |
last post by:
Hi all,
I was wondering if anyone can help me with a really annoying problem I have
been having. I made a derived datagrid class that will select the row when
a user clicks anywhere on a cell...
|
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID ...
|
by: MurdockSE |
last post by:
Greetings.
My Situation:
// I have an .xml file that I am reading into a dataset in the
following code -
DataSet ds = new DataSet("MyDataset");
ds.ReadXml(@"c:\data\"+cmyxmlfilename);
|
by: Jimmy |
last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far:
<%
Dim oConn, oRS, randNum
Randomize()
randNum = (CInt(1000 * Rnd) + 1) *...
|
by: MP |
last post by:
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source="...
|
by: Matthew Wells |
last post by:
I have a listbox set to simple multi select. For this example, users only
select one item at a time. I have command buttons on the form for First,
Previous, Next, Last, New (record). The form...
|
by: plaster1 |
last post by:
Been trying to come up with a query to filter-down my sample set into
distinct records. For instance, lets say column1 is a sample set,
column2 is the parameter, and column3 is a name and column4...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
| |