473,804 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having a problem limiting results of query

11 New Member
Hi,
I want my query to go through all the employee hours and list the associated rates for each record. This means going through Eng_Costing and linking to Eng_PrjGrds (matching Project and Grade), then linking to Eng_Rate using Rate ID.

Expand|Select|Wrap|Line Numbers
  1. SELECT Eng_Phase.Phs_MainPrj, Eng_Costing.CST_Grade, Eng_Costing.CST_Date, Eng_Costing.CST_Norm_H, Eng_Costing.CST_OT_H, Eng_Costing.CST_OTX_H, Eng_Rate.RT_Norm, Eng_Rate.RT_OT, Eng_Rate.RT_OTX
  2.  
  3. FROM Eng_Rate INNER JOIN Eng_PrjGrds ON Eng_Rate.RT_ID = Eng_PrjGrds.PRJGRD_RateID, Eng_Costing INNER JOIN Eng_Phase ON Eng_Costing.CST_Phase = Eng_Phase.Phs_Auto
  4.  
  5. WHERE (((Eng_Rate.RT_DtFrm)<=[eng_costing].[cst_date]) AND ((Eng_PrjGrds.PRJGRD_Prj)=[eng_phase].[phs_mainprj]) AND ((Eng_PrjGrds.PRJGRD_Grade)=[eng_costing].[cst_grade]) AND ((Eng_Costing.CST_OverHead)=False))
  6.  
  7. ORDER BY Eng_Phase.Phs_MainPrj, Eng_Rate.RT_DtFrm DESC;
  8.  
My problem is this, Eng_Costing has around 3500 records and the query returns about 6000. It is caused by the value RateID having duplicate entries in the Eng_Rate table, these duplicate entries are necessary to allow the continuous updating of Rates charged to customers.
I need the query to only return one Eng_Rate record for each Eng_Costing record, the Eng_Rate record I want is the first one found.

If anyone has any ideas...please feel free to suggest them.
I thought about perhaps using 'Distinct' or 'Top 1', but obviously either i'm putting them in the wrong place or they just aren't suitable for this.

I'm using Access 2003 on XP.
Oct 10 '07 #1
3 1423
DDonnachie
11 New Member
Nevermind folks....solved

I changed the query to call a function which locates the rate for each record, not quite what I was originally hoping for but.....it works :)
Oct 10 '07 #2
nico5038
3,080 Recognized Expert Specialist
For the requirement:
"I need the query to only return one Eng_Rate record for each Eng_Costing record, the Eng_Rate record I want is the first one found."
You could have used a GroupBy query with the "First" option for the value needed.

Nic;o)
Oct 10 '07 #3
DDonnachie
11 New Member
thanks Nico
I'll give it a try when I get a chance.....it might speed up the query a bit.
Oct 11 '07 #4

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

Similar topics

6
2229
by: Kingdom | last post by:
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car' and the second box will list all the car 'manufacturers' and the display will then provide all the rest of the info from the other fields. I need to eliminate all the duplicates in the First Drop Down as it currently displays an entry for every record, many are identical, I might have over...
1
5374
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime), acgr.group_code, bank.local_acc_no, bank.short_name,
1
1583
by: sks | last post by:
Hi, I have a products table which apart from other things has a column called manufacturer. I want to run a query that returns x number of products PER manufacturer for each manufacturer that matches some criteria. table::products -------- id
25
3393
by: Tom Leylan | last post by:
Help :-) I can't see how this should be laid out! Consider the scenario of a car rental company. They have "cars" and "lots" (nationwide) and "customers." So far it is easy to query each of these. A car is rented by a customer so there would be say a "rentals" table. A car is rented and returned over and over so there would be many rentals for each car. One thing to remember is that the car isn't assigned to a specific lot so...
1
1223
by: k k | last post by:
Hi, The following query has failed to return all the records. SELECT b.Account_desc, b.Account, IIf(a.source_type = 'LY01', a.CSPL_CSPL,0), IIf(a.source_type = 'LY01', a.CSPL_CMS,0), IIf(a.source_type = 'LY01', a.CSPL_CMM,0), IIf(a.source_type = 'LY01', a.CSPL_CMT,0) from Actual_data_final a right outer join Actual_account_Tbl b on a.Account_desc = b.Account_desc
20
2516
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using insert-statements. after initalizing and starting postgres 7.4 on a different port and datadirectory, i tried to import the sql-dump with the copy statements. this import fails, but importing the dump-file with inserts took a long time but was...
2
1274
by: mpar612 | last post by:
Hi everyone, The code posted below retrieves all of the rows from a database table. It paginates them by limiting to 20 results per page. It is supposed to print 5 rows of results with 4 results per row. Everything works fine, except the first row returned from the database is never printed. It doesn't matter how the results are ordered or how many rows are in the db, the first row that is supposed to be printed is not printed. Does...
15
1799
by: Hexman | last post by:
Hello All, How do I limit the number of detail records selected in a Master-Detail set using SQL? I want to select all master records for a date, but only the first 3 records for the details (based on the primary key of the detail record). I've been trying with "TOP 3", but can't get anywhere. Using Access 2000. Something like: SELECT t1.*, TOP 3 t2.*
1
4468
by: JustinCarmony | last post by:
I'm using a DataAdapter to fill a DataSet to display a list of items in a custom way. I'm not using the GridView or any server controls like that. This is my code: <code> SqlConnection sqlConn = DatabaseControl.Database.GetConnection(Globals.dbConn); SqlCommand cmdTitles = new SqlCommand(); cmdTitles.CommandText = "SelectTitlesByCategory";
0
10600
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...
0
10352
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...
0
10097
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...
1
7642
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
6867
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
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
3835
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.