473,789 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Current Location Query (Recently Posted as Please Help)

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.
Nov 13 '05 #1
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.


Nov 13 '05 #2
"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"

Nov 13 '05 #3

"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
Nov 13 '05 #4
> 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

Nov 13 '05 #5

"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

Nov 13 '05 #6
Thanks Guys, It works great now. I wasn't linking all of the
informatio that I needed .
Nov 13 '05 #7

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

Similar topics

2
5351
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:
2
1644
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,
7
2580
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
8
1934
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...
14
3502
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...
3
10842
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...
1
1856
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).
1
3201
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();
2
2628
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?
0
9663
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
10404
Oralloy
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...
1
10136
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
9979
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
9016
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...
1
7525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
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...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2906
bsmnconsultancy
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...

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.