I have had alot of problems with my query, I have a two tables of
informations and just need a simple Query to get what I want but it is
turning out not to be so simple.
Table 1 Has the following information
TransactionNumb er LocationSer RMANumber TimeandDate
1 0000045679 234567 10/10/2004 1:30:45PM
2 0000023456 234567 10/10/2004 2:30:24PM
3 0000045679 234678 10/10/2004 11:30:25AM
Table 2 Has this information
LocationSer LocationName
0000045679 Recieving
0000023456 Inspection
What I am trying to do is create a query, or a series of queries, that
will give me the CURRENT location for every RMANumber(witho ut
duplicating the RMANumber). I would like it to resemble this
RMANumber Location
234567 Inspeaction
234678 Recieving
Please notice that the RMANumber occurs only once in the query but
twice in Table1.I am probably over thinking the problem. The answer
can be in SQL or Access directions. Any help will be greatly
appreciated. Once I see it done correctly I am sure it will become
obvious. 6 1507
On 15 Oct 2004 19:51:03 -0700, he****@gmail.co m (Mike) wrote:
Try this (off the top of my head - excuse minor syntax issues). Some
SQL gurus will do this in 1 query. I prefer to maintain my sanity and
break the problem down in bite-size chunks.
First create a query that gets the most recent date for each RMA:
Select RMANumber, max(TimeAndDate )
from table1
group by RMANumber
Then create a second query to pick up the LocationSer for each record
in query1. Put both query1 and table1 on the design surface, and inner
join both RMANumber and TimeAndDate:
select LocationSer, query1.*
from table1 inner join query1 on
table1.RMANumbe r=query1.RMANum ber and table1.TimeAndD ate =
query1.TimeAndD ate
Then a third query will pull the LocationName:
(btw, that's spelled 'Receiving')
Put both query2 and table2 on the design surface, and inner join by
LocationSer:
select query2.RMANumbe r, table2.Location
from query2 inner join table2 on
query1.Location Ser = table2.Location Ser
-Tom. I have had alot of problems with my query, I have a two tables of informations and just need a simple Query to get what I want but it is turning out not to be so simple. Table 1 Has the following information
TransactionNum ber LocationSer RMANumber TimeandDate 1 0000045679 234567 10/10/2004 1:30:45PM 2 0000023456 234567 10/10/2004 2:30:24PM 3 0000045679 234678 10/10/2004 11:30:25AM
Table 2 Has this information
LocationSer LocationName 0000045679 Recieving 0000023456 Inspection
What I am trying to do is create a query, or a series of queries, that will give me the CURRENT location for every RMANumber(witho ut duplicating the RMANumber). I would like it to resemble this
RMANumber Location 234567 Inspeaction 234678 Recieving
Please notice that the RMANumber occurs only once in the query but twice in Table1.I am probably over thinking the problem. The answer can be in SQL or Access directions. Any help will be greatly appreciated. Once I see it done correctly I am sure it will become obvious.
"Mike" <he****@gmail.c om> wrote in message
news:53******** *************** ***@posting.goo gle.com... I have had alot of problems with my query, I have a two tables of informations and just need a simple Query to get what I want but it is turning out not to be so simple. Table 1 Has the following information
TransactionNumb er LocationSer RMANumber TimeandDate 1 0000045679 234567 10/10/2004 1:30:45PM 2 0000023456 234567 10/10/2004 2:30:24PM 3 0000045679 234678 10/10/2004 11:30:25AM
Table 2 Has this information
LocationSer LocationName 0000045679 Recieving 0000023456 Inspection
What I am trying to do is create a query, or a series of queries, that will give me the CURRENT location for every RMANumber(witho ut duplicating the RMANumber). I would like it to resemble this
RMANumber Location 234567 Inspeaction 234678 Recieving
Please notice that the RMANumber occurs only once in the query but twice in Table1.I am probably over thinking the problem. The answer can be in SQL or Access directions. Any help will be greatly appreciated. Once I see it done correctly I am sure it will become obvious.
select t1.RMANumber, t2.LocationName
from Table1 as t1
inner join Table2 as t2
on t1.LocationSer = t2.LocationSer
where t1.TimeandDate =
(
select max(t3.TimeandD ate)
from Table1 as t3
where t3.RMANumber = t1.RMANumber
)
I suggest giving your tables name which are meaningful like "transactio ns"
and "locations"
"Mike" <he****@gmail.c om> skrev i en meddelelse
news:53******** *************** ***@posting.goo gle.com... I have had alot of problems with my query, I have a two tables of informations and just need a simple Query to get what I want but it is turning out not to be so simple. Table 1 Has the following information
TransactionNumb er LocationSer RMANumber TimeandDate 1 0000045679 234567 10/10/2004 1:30:45PM 2 0000023456 234567 10/10/2004 2:30:24PM 3 0000045679 234678 10/10/2004 11:30:25AM
Table 2 Has this information
LocationSer LocationName 0000045679 Recieving 0000023456 Inspection
What I am trying to do is create a query, or a series of queries, that will give me the CURRENT location for every RMANumber(witho ut duplicating the RMANumber). I would like it to resemble this
RMANumber Location 234567 Inspeaction 234678 Recieving
Please notice that the RMANumber occurs only once in the query but twice in Table1.I am probably over thinking the problem. The answer can be in SQL or Access directions. Any help will be greatly appreciated. Once I see it done correctly I am sure it will become obvious.
SELECT Table1.Location Ser, Last(Table2.Loc ationName)
FROM Table1 INNER JOIN Table2 ON Table1.Location Ser = Table2.Location Ser
GROUP BY Table1.Location Ser
The use of this simple query is based on the assumption that the
transactions are entered as they occur, ie in ascending time order. Then the
use of LAST would ensure that the latest (and current) location is selected.
If this requirement cannot be guarantied, the more complex query proposed by
John Winterbottom is better.
Regards,
Kaj
> SELECT Table1.Location Ser, Last(Table2.Loc ationName) FROM Table1 INNER JOIN Table2 ON Table1.Location Ser = Table2.Location Ser GROUP BY Table1.Location Ser
Oops, sorry. Wrong field selected/grouped. The correct query is of course
SELECT Table1.RMANumbe r, Last(Table2.Loc ationName)
FROM Table1 INNER JOIN Table2 ON Table1.Location Ser = Table2.Location Ser
GROUP BY Table1.RMANumbe r
"Kaj Julius" <ju******@lindb jergparken.nosp m.dk> skrev i en meddelelse
news:41******** *************@d read11.news.tel e.dk... SELECT Table1.Location Ser, Last(Table2.Loc ationName) FROM Table1 INNER JOIN Table2 ON Table1.Location Ser = Table2.Location Ser GROUP BY Table1.Location Ser
Oops, sorry. Wrong field selected/grouped. The correct query is of course
SELECT Table1.RMANumbe r, Last(Table2.Loc ationName) FROM Table1 INNER JOIN Table2 ON Table1.Location Ser = Table2.Location Ser GROUP BY Table1.RMANumbe r
Oh man, I'm getting old and stupid!!! Okay, third try
SELECT Last(Table1.RMA Number), Table2.Location Name
FROM Table1 INNER JOIN Table2 ON Table1.Location Ser = Table2.Location Ser
GROUP BY Table2.Location sName
Hopefully this ship sails...
Regards,
Kaj
Thanks Guys, It works great now. I wasn't linking all of the
informatio that I needed . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Fountain |
last post by:
We've recently enabled slow query logging on a server and it's proving
interesting seeing which queries are bogging things down. This one is
puzzling me a little:
SELECT articleid, type, authorid, authorname, text, posted FROM
comments WHERE status = 'normal' ORDER BY posted DESC LIMIT 5;
The purpose of this query is to list the five most recent
(non-deleted) comments. Here is the table structure:
|
by: John Paine |
last post by:
Hi All,
I've been struggling with how best to define a query to get a list of unique
coordinates from a database table and my SQL skills are not good enough to
work out a good solution. The basic table structure is as follows:
CREATE TABLE (
CY DOUBLE,
PY DOUBLE,
C1X DOUBLE, C2X DOUBLE,
|
by: Dave Hopper |
last post by:
Hi
I posted a question recently regarding problems I am having getting a
value from a list box to use in a query. I got a lot of help, for
which I thank you and it's nearly working! But I need a little more
help on one more point.
This is what i've got. I have code that hunts for updated
appointments in a public folder based on the order that happens to be
open (code fires on an on open event) This works fine and updates my
|
by: Vince Morgan |
last post by:
Hi,
I'm not sure that I have the right group, so please bear with me.
Recently I created a fuction in the MS Access VBA IDE. The function returns
a Boolean.
I created the function to use as criteria in an Access query, and then I
discovered a problem.
The query runs ok, but it's apparently ignoring the functions return val.
It doesn't matter whether the function returns true, or false. If I
remember correctly (I haven't worked on it...
|
by: Tina |
last post by:
My employer tracks productivity/performance of clinicians (how much
they
bill) each week, its averages for the month, and the 6 months.
These averages are compared to their expected productivity.
However, the expectation changes - it may be 60% for a while, then
change to
50%. Initially, I was averaging the expectation, along with the
productivity, but what I'm being asked is to look at the average
productivity/performance compared to...
| |
by: namewitheldbyrequest |
last post by:
"The XML element 'EnableTheming' from namespace 'http://tempuri.org/'
is
already present in the current scope"
I created a Web Service: I imported System.Data.SqlClient so I could
access SQL server tables programmatically. The web service builds and
deploys with no problems. When I try to add the corresponding Web
Reference to the Web Site project I get the error listed below.
I am able to create other Web Services on the same server...
|
by: Chris Lincoln |
last post by:
Hello,
I can't quite seem to figure out this issue; it is specific to Firefox,
as it works fine in IE.
I have an iFrame within an aspx page that is passed a value in the
query string (e.g. /index.aspx?query=about%20us). What
happens (in IE at least!) is that upon load, a textbox is filled with
the querystring and a search function is executed (search function is
not an issue).
|
by: simbarashe |
last post by:
Hie
could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as follows:
The code below is for the first page:session_start is in line 3
<link href="css/jobSheet.css" rel="stylesheet" type="text/css" />
session_start();
|
by: Kakkanattu |
last post by:
Hi,
In desktop application, we use different ways to get the current
execution directory.
I. AppDomain.CurrentDomain.BaseDirectory
II. Environment.CurrentDirectory
III. Directory.GetCurrentDirectory()
IV. Assembly.GetExecutingAssembly().Location
Can u please help me to know the difference of all these? Also is
there any other way to get the current directory other than the above?
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
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...
|
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...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |